Automate

 View Only
  • 1.  Javascript - Change Background Color on Changed Fields

    Posted 4 hours ago

    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
    ------------------------------


  • 2.  RE: Javascript - Change Background Color on Changed Fields

    Posted 2 hours ago

    Hi Kurt,

    I have a similar web-form for customer master changes that pulls the current data from SAP, then as the user interacts with the form, the highlighting happens. I think you are saying your form highlights will run as soon as your web-service returns the data, as the fields get triggered by being populated, hence the timing issue. I agree, as this is something we previously encountered when we first created this solution. My rules are not Java script, but easy conversions to what you need.

    Here are a list of things I have done to help reduce chances of "pre-highlighting"
    1) initially only give users enough input fields to retrieve the CM data


    2) Once Data is pulled, user needs to tick which section (General, CoCd, or Sales) data structures they need – bonus: ticking one 'Update' ticks all, which helps in our workflow

    3) The Update _____ Data tick box is used conditionally as part of my two rules on the field I want to highlight – 1 action, 1 formatting. Using a similar "hidden" CI – Change indicator field, as you are.

    4) User changes the field and it will turn yellow

    5) Lastly, assuming this is workflowed to other teams for review/final execution to SAP and IF those views are different than your origination view, I recommend copying the formatting rule from the field to each additional view you need to see it on. First rule is not needed, as your "hidden" field is already set accordingly.

    -   Two notes: This step can be ignored if you use the same view across all teams OR do not have a workflow. Run this rule on form load for other reviewers, to ensure it highlights automatically.
     



    ------------------------------
    Jeremy Maxfield
    Lead BSA
    Chamberlain Group, LLC
    Oak Brook IL
    ------------------------------