I am looking for a way to change the background color of fields that have had their values changed and have attempted this, but I have a timing/theory issue that causes all the fields to change background color.
My setup:
Each field on the form has a duplicate field not visible to the user that has _Read appended on it. Example Sales Org / Sales Org_Read, Distribution Channel / Distribution Channel_Read etc.
On form initialize there are several fields that gather the users input and a button "Get Data" is clicked that runs a series of 7 webservices that fills in specific fields in the rest of the form. The "Get Data" button also runs a script "copyToReadFields" that is suppose to kick off from a rule from the last webservices LogField that copies each fields values to it's respective _Read fields so they both have the same value.
The highlightSelf() script below appears to be running before all the fields have had the chanced to be copied.
Any thoughts on how to fix this?
Thanks,
Kurt
function copyToReadFields() {
debugger;
// Get a list (array) of field xPaths that end with the text "_Read"
var readFields = $form.formModel.getFormFields(false).filter(function (xPath) { return /_Read$/.test(xPath) } );
// Iterate through each element of the list of xPaths
readFields.forEach(function (readXPath) {
// * Generate the xPath of the write field based on the name of the Read field
// Remove "_Read" from the end of the xPath
var writeField = readXPath.replace(/_Read$/, '');
// Remove the beginning of the xPath (the path), leaving only the name of the field
writeField = writeField.substring(writeField.lastIndexOf('/my:') + 4);
// Find the write field xPath based on the field name obtained in the previous step
writeField = getFieldXPath(writeField);
var value = $form.getValue(writeField);
//console.log('readXPath:', readXPath, 'writeField:', writeField, 'value:', value);
$form.setValue(readXPath, value);
// Get the value of the read field and copy it into the write field.
$form.setValue(readXPath, $form.getValue(writeField));
});
}
Each field is assigned highlightSelf() as a rule.
function highlightSelf() {
debugger;
$form.setLabel(ruleFieldInfo.XPath,'',true);
if($form.getValue('/my:myFields/my:LogField_18') != ''){
var highlight = '#aea935';
var fontColor = '#000000';
var subMessage = "Current SAP Data: ";
var readField = ruleFieldInfo.XPath;
readField = readField.substring(readField.lastIndexOf('/my:') + 4) + '_Read';
readField = getFieldXPath(readField);
var checkfield = ruleFieldInfo.XPath;
var a = $form.getValue(checkfield);
var b = $form.getValue(readField);
if ($form.getValue(ruleFieldInfo.XPath) != $form.getValue(readField)) {
$form.setStyle(ruleFieldInfo.XPath,'background-color', highlight);
$form.setStyle(ruleFieldInfo.XPath,'color', fontColor);
$form.setLabel(ruleFieldInfo.XPath,subMessage + $form.getValue(readField),true);
} else {
$form.setStyle(ruleFieldInfo.XPath,'background-color', '');
$form.setStyle(ruleFieldInfo.XPath,'color', '');
$form.setLabel(ruleFieldInfo.XPath,'',true);
}
}
}
------------------------------
Kurt Marshman
Old World Industries, LLC
------------------------------