Autocomplete a field by verifying the value of another field.

Garvia
Tera Contributor

Hello everyone, I have this problem: I want to create a client script that checks the value of a field and, depending on its value, autocompletes another field with the values I specify below. It works this way, but I’d like to avoid using the sys_id. However, when I retrieve the value of the reference fields, the value returned is the sysid. Could you help me find another way to do this?

 

 

function onSubmit() {
  
    if (g_form.getValue('role_1_vs') == '4262f61587b3d55051aded773cbb35c1' && g_form.getValue('need_vs') == '34854ee9dbeee8500893304d3b9619c7') {
        g_form.setValue('domain_2_vs', 'adgbs.com');
    }

    if (g_form.getValue('role_1_vs') == '8e62f61587b3d55051aded773cbb35ba' && g_form.getValue('need_vs') == '34854ee9dbeee8500893304d3b9619c7') {
        g_form.setValue('domain_4_vs', '@bsabadell.onmicrosoft.com');
    }    
}

 

4 REPLIES 4

Mark Manders
Mega Patron

A reference field always contains the sys_id of the record it's from, so why do you want to avoid it? If you add some comments to your script of what they are from, you will have made it easy for others to understand what it is.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

 

I don't think it's good practice to use sys id in scripts... That's why I'm unsure whether to use them or not.

Ankur Bawiskar
Tera Patron
Tera Patron

@Garvia 

you are hard-coding sysIds which is not recommended.

Also why not have 2 onChange client scripts with GlideAjax, 1 on role_1_vs and 1 on need_vs

You can easily set the value to your variables using this.

You can use system property to store those hard-coded sysIds and then compare within GlideAjax script include.

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

@Garvia 

Thank you for marking my response as helpful.

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