The CreatorCon Call for Content is officially open! Get started here.

Compare Drop down and String Value

Pankaj15
Tera Contributor

Hi Team,

 

Create a 2 fields in the Custom table:

Risk Level: choice[Critical, High, Medium and Low]

Barr Level: String Only set Value[Critical, High, Medium and Low]

 

Requirement: compare the Barr Level  is Higher then the Risk Level.

 

 

 

1 ACCEPTED SOLUTION

Maddysunil
Kilo Sage

@Pankaj15 

you can use a Business Rule or a Script Include to compare the values of the "Risk Level" and "Barr Level" fields whenever a record is inserted or updated in the custom table.

 

 

(function executeRule(current, previous /*null when async*/) {

    // Get the values of Risk Level and Barr Level
    var riskLevel = current.getValue('risk_level');
    var barrLevel = current.getValue('barr_level');

    // Map the text values to their corresponding numerical values
    var riskLevelValue = getNumericValue(riskLevel);
    var barrLevelValue = getNumericValue(barrLevel);

    // Compare the values
    if (barrLevelValue < riskLevelValue) {
        // Barr Level is lower than Risk Level
        gs.addErrorMessage("Barr Level cannot be lower than Risk Level.");
        current.setAbortAction(true); // Abort the transaction
    }

    // Function to map text values to numerical values
    function getNumericValue(level) {
        switch (level) {
            case 'Critical':
                return 4;
            case 'High':
                return 3;
            case 'Medium':
                return 2;
            case 'Low':
                return 1;
            default:
                return 0; // Default value or error handling
        }
    }

})(current, previous);

 

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

View solution in original post

6 REPLIES 6

Danish Bhairag2
Tera Sage

Hi @Pankaj15 ,

 

Could u please elaborate ur requirement , as it is not very clear when u say compare barr level with risk level

 

Thanks,

Danish

Yes , compare Bar Level with risk Level

 

Bar Level: Critical ,High, Medium and Low

Risk Level: Critical ,High, Medium and Low

@Pankaj15 

 

So is it something like if risk level is high then Barr level should be set to High?

 

Thanks,

Danish

Rishi_11
Kilo Sage

Hi @Pankaj15 

 

Do you want Bar level to be always higher than Risk level? If yes, you can write a Onchange client script on Bar level field, here you can check the value of Risk level and then if Bar level is lower than Risk level you can display an error message and clear the value from the field.

Let me know if I was able to understand your requirement clearly or if you need any help with the script.

 

Please mark this response helpful or correct, if it helped you.

Regards,

Rishi.