Business Rule not returning same value as Background script.

Aaron Duncan
Mega Sage

I have the following script that when run as a background script, runs perfectly. When I place it in an After Business Rule, the values for the conditions are no longer the same as when they were in the business rule. The variables in the IF statements return false on the Business Rule. There is another business rule that runs before this that sets the field values that this depends upon.

 

    // Decision Table Builder code to take the fields and pass them through to the Decision Table for Legal Category assignment.
    try {
        var inputs = {};
        inputs['u_data_selected'] = current.u_if_customer_pii_data_selected.getDisplayValue(); // String 
        inputs['u_customer_characteristics'] = current.u_cpii_customer_characteristics.getDisplayValue(); // String 
        inputs['u_medical_insurance_information'] = current.u_cpii_medical_insurance_info.getDisplayValue(); // String 
        inputs['u_commercial_information'] = current.u_cpii_commercial_information.getDisplayValue(); // String 
        inputs['u_internet_communication_activity'] = current.u_cpii_internet_comm_activity.getDisplayValue(); // String 
        inputs['u_biometric_information'] = current.u_cpii_biometric_information.getDisplayValue(); // String 
        inputs['u_geolocation_information'] = current.u_cpii_geolocation_information.getDisplayValue(); // String 
        inputs['u_sensory_data'] = current.u_cpii_sensory_data.getDisplayValue(); // String 
        inputs['u_employment_education_information'] = current.u_cpii_employment_education_information.getDisplayValue(); // String 
        inputs['u_inferences'] = current.u_cpii_inferences.getDisplayValue(); // String 

        var dt = new sn_dt.DecisionTableAPI();
        var response = dt.getDecisions('5f86416e93a94210561430747aba1073', inputs);

        for (var i = 0; i < (response && response.length); i++) {
            var result = response[i];
			gs.info('Legal Categories Result: ' + result);
            var result_elements = result.result_elements;
            var u_biometric_information = result_elements.u_biometric_information; // True/False
            var u_commercial_information = result_elements.u_commercial_information; // True/False
            var u_geolocation_information = result_elements.u_geolocation_information; // True/False
            var u_identifiers = result_elements.u_identifiers; // True/False
            var u_inferences = result_elements.u_inferences; // True/False
            var u_internet_network_activity = result_elements.u_internet_network_activity; // True/False
            var u_none = result_elements.u_none; // True/False
            var u_sensory_data = result_elements.u_sensory_data; // True/False
            var u_sensitive_personal_information = result_elements.u_sensitive_personal_information; // True/False
            var u_protected_classification_characteristics = result_elements.u_protected_classification_characteristics; // True/False
            var u_professional_employment_info = result_elements.u_professional_employment_info; // True/False
            var u_other_personal_information = result_elements.u_other_personal_information; // True/False

            if (u_biometric_information == true) {
                current.u_biometric_information = true;
            }
            if (u_commercial_information == true) {
                current.u_commercial_information = true;
            }
            if (u_geolocation_information == true) {
                current.u_geolocation_information = true;
            }
            if (u_identifiers == true) {
                current.u_identifiers = true;
            }
            if (u_inferences == true) {
                current.u_inferences = true;
            }
            if (u_internet_network_activity == true) {
                current.u_internet_network_activity = true;
            }
            if (u_sensory_data == true) {
                current.u_sensory_data = true;
            }
            if (u_sensitive_personal_information == true) {
                current.u_sensitive_personal_information = true;
            }
            if (u_professional_employment_info == true) {
                current.u_professional_employment_info = true;
            }
            if (u_other_personal_information == true) {
                current.u_other_personal_information = true;
            }
            if (u_protected_classification_characteristics == true) {
                current.u_protected_classification_characteristics = true;
            } 
	current.setWorkflow(false);
        current.update();
        }
        current.update();
        if (current.u_biometric_information == false && current.u_commercial_information == false && current.u_geolocation_information == false && current.u_identifiers == false && current.u_inferences == false && current.u_internet_network_activity == false && current.u_sensitive_personal_information == false && current.u_sensory_data == false && current.u_other_personal_information == false && current.u_professional_employment_info == false && current.u_protected_classification_characteristics == false) {
            current.u_none == true;
            current.update();
        }

    } catch (e) {
        gs.warn("Couldn't run this script Error: " + e)
    }

 

6 REPLIES 6

At face value, if you're needing to selectively take results from the decision table, it sounds like the decision table needs restructuring. As an example, what's if you're later presented with a query on why a record had certain field values set, you'd have to spend a lot of time working out which decision table results were used. 

I ended up going down the Flow route and it was able to process everything correctly.