How to add an choice using the serverside script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 06:23 AM
Hello! Iam new to Servicenow, I have one requirement that i have one field called software name which was an choice list type
that also i have another field called other. when the other field was filled that i want to add these field value to the choice list of software name field.basically that i want to add an choice to the field using server side script . it was one of the requirement of my workflow task. That i have written some code,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2025 09:16 AM
Hlo @Fahimas,
Hope you are doing well.
Proposed Solution
In order to achieve this task and to give you an appropriate solution of this problem, I personally tried and implemented it on my Personal Developer Instance so that you can get an appropriate solution as soon as possible. For this, what I did I wrote my own server-side code/script using Background Script, and tried to update the label like you are doing and it seems to be working fine for me and I believe that it'll work for you as well. Hence, pasting my code down below that you can refer and update whereever you want to maybe in the Workflow or somewhere else.
Server Side Script
var grChoice = new GlideRecord("sys_choice");
grChoice.addQuery("name", "u_custom_users");
grChoice.addQuery("element", "u_software_name");
grChoice.addQuery("label", "Slack");
grChoice.query();
if (grChoice.next()) {
// gs.info(gr.label);
grChoice.label = 'Slack2';
grChoice.update();
}
For your reference and just to show you the results, also attaching snapshots of the outputs that will give you better insights of how the script is working or the best thing will be to follow the solution and execute the scripts on your instance.
Before Running the Script
Background Script
After Running the Script
If you find this information/knowledge/solution helpful, please don't forget to mark my solution as helpful and Accepted as a Solution.
Thanks 🙂
Aakash Garg
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 07:49 AM
Thanks for your response. But I want to add the value as another choice in the field .
You are comparing that slack was there and you are adding that choice in the place of slack.litetrally I don't want that.basically I want to add an value as choice to the choice field in catalog item .sry that I didn't mentioned catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2025 02:06 AM
I was done some script which wasn't worked out !!