Business Rule Action set field value not working

Vengeful
Mega Sage

We receive a requirement in Change Request that during creation of CR if the user select SAP-AMK in Subcategory 1 the COE must to auto-populate to SAP.

Merza_3-1699601643657.png

 

 

I created a BR see screenshot

When to run

Merza_0-1699601352405.png

 

Actions

Merza_1-1699601400541.png

 

When I tried it, it's not working

Merza_2-1699601591530.png

 

 

 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Vengeful 

to see it happen real-time you need to use 2 onChange client scripts 1 on Subcategory1 and 1 for type field

I would recommend using business rule rather than use 2 onChange scripts

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

Kavita_Bhojane
Tera Guru

Hi @Vengeful,

 

Try using on change client script on SubCategory 1 :

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
 
    //Type appropriate comment here, and begin script below
    
if(newValue == "SAP-AMK"){
g_form.setValue("coe", "SAP");
}
    else{
g_form.setValue("coe", "");
}
}
 
Screenshot 2023-11-14 at 11.08.40 AM.png

 

Use Field Name as "SubCategory 1" in the above client script

 

Please mark my answer helpful and correct if you find it useful.

 

Thanks,

Kavita Bhojane

View solution in original post

13 REPLIES 13

Hi @Ankur Bawiskar 

Yes, no other BR.

My only concern now is that during submission (New), once I select Subcategory 1 to SAP-AMK, the COE is not populating.

Merza_0-1699933478786.png

 

Since the COE is mandatory, I tried to select other value like AMS

Merza_1-1699933572847.png

Merza_2-1699933615750.png

After submitted, the COE became SAP.

Merza_3-1699933708916.png

Merza_4-1699933725164.png

 

Kavita_Bhojane
Tera Guru

Hi @Vengeful,

 

Try using on change client script on SubCategory 1 :

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
 
    //Type appropriate comment here, and begin script below
    
if(newValue == "SAP-AMK"){
g_form.setValue("coe", "SAP");
}
    else{
g_form.setValue("coe", "");
}
}
 
Screenshot 2023-11-14 at 11.08.40 AM.png

 

Use Field Name as "SubCategory 1" in the above client script

 

Please mark my answer helpful and correct if you find it useful.

 

Thanks,

Kavita Bhojane

Thank you so much @Kavita_Bhojane 

Hi @Vengeful,

 

Could you please mark my answer helpful?

 

Thanks,

Kavita Bhojane