"How to Update a Reference Field (sys_user_group) Using a String Field in ServiceNow?"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 04:16 AM
Hello Community,
I’m working on a requirement in ServiceNow where I need to update a reference field (value1) that points to the sys_user_group table. The value to update this reference field comes from another field (value) which is of type string.
The value field contains the name or some identifier of the group that exists in the sys_user_group table. I need to convert this string into a reference and set it in the value1 field programmatically (e.g., using a script).
Could anyone guide me on the best approach to achieve this? Are there any specific GlideRecord operations or other methods I should use to query the sys_user_group table and update the reference field correctly?
Any examples or best practices would be greatly appreciated!
Thanks in advance for your help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 07:16 AM
Is your value that you have a sys_id? Or is it the display value? If it's a sys_id, then you can just assign it directly.
current.value1 = value; //for a server-side script
g_form.setValue('value1', value); //for a client-side script
If it's a display value, you can use this:
current.setDisplayValue('value1', value); //for server-side script
g_form.setDisplayValue('value1', value); //for client-side script