Business rule is not working

Jyothsna5
Tera Expert

Conditions were met and business rule is executing not it's not displaying proper result, please refer below given condition

Jyothsna5_0-1766031020065.png

 

and the script is

(function executeRule(current, previous) {

    // HIGH RISK
    if (
        current.u_information_security == 'no' &&
        current.u_network_security == 'no' &&
        current.u_did_supplier_have_any_history_of_aml == 'yes' &&
        current.u_is_supplier_has_any_history_of_cyber_crime == 'yes' &&
        current.u_supplier_compliant_with_jurisdictions_rules_and_regulations== 'no'
    ) {
        current.u_inherent_risk_rating = 'high';
    }

    // MEDIUM RISK
    else if (
        (
            current.u_information_security == 'no' ||
            current.u_network_security == 'no'
        ) &&
        (
            current.u_is_supplier_has_any_history_of_cyber_crime == 'yes' ||
            current.u_did_supplier_have_any_history_of_aml == 'yes' || current.u_supplier_compliant_with_jurisdictions_rules_and_regulations== 'no'
        )
    ) {
        current.u_inherent_risk_rating = 'medium';
    }

    // LOW RISK
    else if (
        current.u_information_security == 'yes' &&
        current.u_network_security == 'yes' &&
        current.u_is_supplier_has_any_history_of_cyber_crime == 'no' &&
        current.u_did_supplier_have_any_history_of_aml == 'no' &&
        current.u_supplier_compliant_with_jurisdictions_rules_and_regulations == 'yes'
    ) {
        current.u_inherent_risk_rating = 'low';
    }

    // NOT APPLICABLE
    else {
        current.u_inherent_risk_rating = 'not_applicable';
    }

})(current, previous);

but after updating the record 'Inherent Risk Rating" field was not updating as per script, could anyone help with this issue?
Jyothsna5_1-1766031278918.png

 



1 ACCEPTED SOLUTION

Jyothsna5
Tera Expert

Thank you all for providing your thoughts.

I made changes to my script there is no "u" in the column name, so I changed the script accordingly and we cannot set values on the current record after it has been saved to the database, so changed when to run as "before". Now it's working.

//

(function executeRule(current, previous) {

    // HIGH RISK
    if (
        current.information_security == 'no' &&
        current.network_security == 'no' &&
        current.did_supplier_have_any_history_of_aml == 'yes' &&
        current.is_supplier_has_any_history_of_cyber_crime == 'yes' &&
        current.supplier_compliant_with_jurisdictions_rules_and_regulations== 'no'
    ) {
        current.inherent_risk_rating = 'high';
    }

    // MEDIUM RISK
    else if (
        (
            current.information_security == 'no' ||
            current.network_security == 'no'
        ) &&
        (
            current.is_supplier_has_any_history_of_cyber_crime == 'yes' ||
            current.did_supplier_have_any_history_of_aml == 'yes' || current.supplier_compliant_with_jurisdictions_rules_and_regulations== 'no'
        )
    ) {
        current.inherent_risk_rating = 'medium';
    }

    // LOW RISK
    else if (
        current.information_security == 'yes' &&
        current.network_security == 'yes' &&
        current.is_supplier_has_any_history_of_cyber_crime == 'no' &&
        current.did_supplier_have_any_history_of_aml == 'no' &&
        current.supplier_compliant_with_jurisdictions_rules_and_regulations == 'yes'
    ) {
        current.inherent_risk_rating = 'low';
    }

    // NOT APPLICABLE
    else {
        current.inherent_risk_rating = 'not_applicable';
    }

})(current, previous);
//
Jyothsna5_1-1766204074192.png

 

Jyothsna5_3-1766204125493.png

 

 

View solution in original post

4 REPLIES 4

Deepak Shaerma
Mega Sage

Hi @Jyothsna5 

What exactly you need to achieve via provided business rule?? A proper requirement will help us to provide the exact solution.


PrashantLearnIT
Tera Sage

Hi @Jyothsna5 

 

Please add conditions for empty like below: 

PrashantLearnIT_0-1766038636442.png

This might solve your purpose.

 

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

Ankur Bawiskar
Tera Patron

@Jyothsna5 

share dictionary config of that yes/no field

I couldn't find such field

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Jyothsna5
Tera Expert

Thank you all for providing your thoughts.

I made changes to my script there is no "u" in the column name, so I changed the script accordingly and we cannot set values on the current record after it has been saved to the database, so changed when to run as "before". Now it's working.

//

(function executeRule(current, previous) {

    // HIGH RISK
    if (
        current.information_security == 'no' &&
        current.network_security == 'no' &&
        current.did_supplier_have_any_history_of_aml == 'yes' &&
        current.is_supplier_has_any_history_of_cyber_crime == 'yes' &&
        current.supplier_compliant_with_jurisdictions_rules_and_regulations== 'no'
    ) {
        current.inherent_risk_rating = 'high';
    }

    // MEDIUM RISK
    else if (
        (
            current.information_security == 'no' ||
            current.network_security == 'no'
        ) &&
        (
            current.is_supplier_has_any_history_of_cyber_crime == 'yes' ||
            current.did_supplier_have_any_history_of_aml == 'yes' || current.supplier_compliant_with_jurisdictions_rules_and_regulations== 'no'
        )
    ) {
        current.inherent_risk_rating = 'medium';
    }

    // LOW RISK
    else if (
        current.information_security == 'yes' &&
        current.network_security == 'yes' &&
        current.is_supplier_has_any_history_of_cyber_crime == 'no' &&
        current.did_supplier_have_any_history_of_aml == 'no' &&
        current.supplier_compliant_with_jurisdictions_rules_and_regulations == 'yes'
    ) {
        current.inherent_risk_rating = 'low';
    }

    // NOT APPLICABLE
    else {
        current.inherent_risk_rating = 'not_applicable';
    }

})(current, previous);
//
Jyothsna5_1-1766204074192.png

 

Jyothsna5_3-1766204125493.png