Adding a choice value to the reference type field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 12:13 AM
Hey,
Creating a record producer form to create a new incident.
I have a caller field in the form that once I select a caller, the position field will display the appropriate values of the caller.
I did this by script include :
And in the Reference qual field I called script include:
I need to add to the values in the Position field a value - other which will be a constant value that will always appear, as soon as the caller selects "other" a new field called "other position" of reference type must be displayed that shows all the positions that exist in the system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 12:53 AM - edited 12-21-2023 12:54 AM
You helped me a lot, I added a new record to the table.
I now need to associate the same new record I created (other) to all the users in the system
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 01:17 AM
Hi @Shir Sharvit ,
The only option is to create the records under that table which you are referring and added records will be displayed.
custom choices on reference won't work.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 01:25 AM - edited 12-21-2023 01:29 AM
Hello @Shir Sharvit ,
I share the same viewpoint on this matter as @Sohail Khilji suggested—considering the alternative solution with a new checkbox.
However, if you still prefer to implement it with your approach, here is the answer to your question: You can push the Sys ID of the new record ("other") which you said that you have just created so add that into the array using the syntax below. Please modify it according to your Sys ID and other variables.
Sample script:
// Add the Sys ID of the "other" record to the end of the array
assetIds.push('276f68f81b5335108390c910604bcb7f');
return 'sys_idIN' + arrayUtil.unique(assetIds).join(',');
},
type: 'AssetFilterUtil'
If you'd like to refer to my complete script include code, please find it below.
var AssetFilterUtil = Class.create();
AssetFilterUtil.prototype = {
initialize: function() {},
getFilteredAssets: function() {
var requestedFor = current.variables.requested_for;
gs.log("REQ FOR - " + requestedFor);
var assetIds = [];
var arrayUtil = new ArrayUtil();
var assetGr = new GlideRecord('alm_asset');
assetGr.addQuery('assigned_to', requestedFor);
assetGr.addQuery('sys_class_name', 'IN', ['alm_hardware', 'alm_consumable']);
assetGr.addQuery('install_status', 'NOT IN', [7, 8]);
assetGr.addQuery('state', 'NOT', 'retired');
assetGr.query();
while (assetGr.next()) {
gs.log("Inside while");
assetIds.push(assetGr.sys_id.toString());
}
// Add the Sys ID of the "other" record to the end of the array
assetIds.push('276f68f81b5335108390c910604bcb7f');
return 'sys_idIN' + arrayUtil.unique(assetIds).join(',');
},
type: 'AssetFilterUtil'
}
Since you didn't include the code in your question apart from the image, I made the changes in my code for your guidance.
Let me know your views on this and Mark Correct if this solves your query and also mark Helpful if you find my response worthy based on the impact.
Regards,
Aniket