Business Rule to update category

tsoct
Tera Guru

I have the below business rule that updates Category in the RITM based on a variable. The script below works fine when the user language is English. However, for users who have French set as lamguage, a new choice appears (in red) instead of selecting from the existing selection (in green). How can this be resolved?

 

 

 

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

    var category = current.variables.category.getDisplayValue();

    if ((current.u_category == '')){
        current.u_category = category;
    }

})(current, previous);

//u_category is a string field with Choice in sys_choice

 

 

tsoct_0-1718732606234.png

 

 

5 REPLIES 5

briannice
Kilo Sage

You can try to use one of the lines below. You need to get the internal value that is used in the database instead of the display value.

#1
var category = current.getValue("category")
#2
var category = current.variables.category
#3
var category = current.category

Community Alums
Not applicable

Hi @tsoct ,

 

current.variables.category fetches the internal value of the category variable directly, so you should update the same.

 

Please try the below script-

(function executeRule(current, previous /*null when async*/ ) {
    var category = current.variables.category; // Using the variable value directly

    if (category && current.u_category == '') {
        current.u_category = category; // Setting the internal value directly
    }
})(current, previous);

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar

Hello @Community Alums ,

 

Instead of category label, it return sys_id like below:

tsoct_0-1718768894714.png

 

Hi @tsoct,

Consider using toSting() method which will help you get the actual value

 

var categoryValue = current.variables.category.toString();