client Script is not working

pavana3
Tera Expert

example i have 2 fields one is reference field if i will select category name based on that category group should display .. I used Onchange client script .. like below

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
var appliref= g_form.getReference('application_category', userlookup);

    function userlookup(appliref) {
       
        g_form.setValue('u_application_category_group', appliref.apm_application_category_group);

    }

    //Type appropriate comment here, and begin script below

}
1. application_category  is the reference field 
2.u_application_category_group  is the text field   -- in this field its displaying sys_id instead of value // this category group also as a reference field how to get value instead og sys_id i tryied getvalue but not available getDisplayValue()
 
If anyone know please help me .
 
1 ACCEPTED SOLUTION

@pavana3 

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

View solution in original post

5 REPLIES 5

SanjanaK
Tera Expert

Hey @pavana3,

 

You can try using

g_form.getDisplayBox('your_field').value;

 

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

Hope the answer helps!

Happy Learning!

This is not working your solution... Nothing is displaying now

palanikumar
Mega Sage

Hi,

g_form.getReference will retrieve only sys_id of the reference field and it does not support dotwalking as well. 

You can achieve desired output by either converting u_application_category_group to reference or use GlideAjax and get the display value.

If you are not sure about GlideAjax, then refer this url:

https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_referenc...

Thank you,
Palani

Ankur Bawiskar
Tera Patron
Tera Patron

@pavana3 

2 ways

1) make the "u_application_category_group" field as reference to sys_user_group

OR

2) use GlideAjax and return the group name instead of sysId, I hope you know how to use GlideAjax

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