Adding a choice value to the reference type field

Shir Sharvit
Tera Contributor

Hey,

 

Creating a record producer form to create a new incident.

ShirSharvit_0-1703145991725.png

 


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 :

ShirSharvit_1-1703146114370.png

And in the Reference qual field I called script include:

ShirSharvit_3-1703146227761.png

 

 

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.

7 REPLIES 7

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

Pavankumar_1
Mega Patron

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.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Aniket Chavan
Tera Sage
Tera Sage

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