Updating a reference type variable

Anu_Arv
Tera Contributor

I have the below variable in a catalog item called from_division.

anithaa_0-1739381601526.png

This variable is auto- populated

anithaa_1-1739381683071.png

I have another variable of type Yes/No called ABC _Employee. If ABC_Employee is yes, then I want to update the from_division variable to a specific value of "ABC" from the department table.  What is the best approach?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Anu_Arv 

if you know the department sysId then simply hard-code but don't use GlideRecord

For best practice, story that sysId in system property and use GlideAjax to get that and then set in client script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    if (newValue == 'Yes')
        g_form.setValue('from_division', 'sysId');
    else
        g_form.clearValue('from_division');

}

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

9 REPLIES 9

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Anu_Arv 

Use the onchange client script and set the value, it's best one.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

@Dr Atul G- LNG I tried using an onchange client script but didn't seem to work. Can you take a look and let me know if you see any issues with my script? It doesn't seem to update the value when the value is set to Yes.

 

Anu_Arv_0-1739459589682.png

 

@AshishKM  need help here.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

@Anu_Arv  

glide query returing any record ?

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution