pre-selected value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 03:10 PM
Hi,
How to pre-selecte value on New Location field with the only one available value.
and my field New Location is Reference
i didn't know how to do that ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 03:38 PM
If the requirement is populate the location field if it is only one based on some criteria/query:
You can use a script include and GlideAjax on Client Script / Catalog Client Script. The Script Include should be client callable and should have a function to do GlideRecord operations and return a location if that is the only one existing as per your query.
On the form, catalog item or record producer..., you can create an OnLoad Client script which would call the previously created function using GlideAjax and based on the return value, you can setValue for the location field (If the script returns a value) or do nothing if the script does not return any value.
You can take a look at the following for GlideAjax and Script Include:
https://www.servicenow.com/community/developer-articles/glideajax-example-cheat-sheet/ta-p/2312430
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2025 01:29 AM
Hi Medi,
I tried your solution but in my code source i am blocked :
i dont' know how to say to select juste one selection when field location has juste one display
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2025 02:49 PM
Hi @mouradhadj-
From your script include, make sure you are return the value as a string.
- If it is JSON, you can do JSON.stringify(YOUR_DATA)
- If it is an array, you can return YOUR_ARRAY.join()
Then on your client script, you can parse your data before you work with it
- For JSON: JSON.parse(answer)
- For Array: answer.split(",")
If it still does not work, please provide screenshots from your script include and client script.
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 08:56 PM
Hi @mouradhadj-
Below link could be helpful:
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.