Autocomplete a field by verifying the value of another field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 04:22 AM
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');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 04:33 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 04:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 04:52 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 05:35 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader