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

Debasis Pati
Tera Guru

Hello @Anu_Arv ,

First of all it's not good practice to use gliderecord on client side please use script include for that.
Secondly if you want to use use getreference instead of gliderecord to achieve the values.

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


Regards,
Debasis

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

@Anu_Arv 

Hope you are doing good.

Did my reply answer your question?

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

Thank you so much. That helped!

Need Help here! Say the end user selects Yes first and then selects No, the value in the from_division field is cleared out. The field from_division is left blank since it is auto-populated when the employee name is selected. How can I get it to populate the department of the selected employee?