Dynamically set List Collector variable from Script Include

AbhirupD
Tera Contributor

Hi

 

I have similar scenario where I am calling a REST Message from my scripts include and getting proper response till that. But I am unable to populate those values in the drop down of the WebUser variable.

 

 

My Scripts Include:

var FetchUserID = Class.create();
FetchUserID.prototype = Object.extendsObject(global.AbstractAjaxProcessor,{
getUserDetails: function() {
 
var groupName = 'GSRAAF-Admin';
var grpRestMessage = new sn_ws.RESTMessageV2('scope.Graph_Fetch_ADGRP', 'Default GET');
grpRestMessage.setStringParameter('group_name', groupName);
 
var grpResponse = grpRestMessage.execute();
var grpResponseBody = grpResponse.getBody();
var parsedGrpResponse = JSON.parse(grpResponseBody);
 
return parsedGrpResponse;
},
 
    type: 'FetchUserID'
});
 
 
My Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
}
 
var env = g_form.getValue('environment');
var ga2 = new GlideAjax('FetchUserID');
ga2.addParam('sysparm_name', 'getUserDetails');
ga2.getXML(function(respe2){
var answer2 = respe2.responseXML.documentElement.getAttribute('answer');
if (answer2) {
var usrGrpResponse = JSON.parse(answer2);
var listCollector = g_form.getControl('webusers');
for (var i = 0; i < usrGrpResponse.value.length; i++) {
var webUsers = usrGrpResponse.value[i];
g_form.addOption('webusers', webUsers.nickname, webUsers.displayName);
}
}
});
 

Response From REST:

{
    "value": [
        {
            "@odata.type": "#microsoft.graph.user",
            "id": "xxxxxx",
            "deletedDateTime": null,
            "accountEnabled": true,
            "ageGroup": null,
            "displayName": "Singha,  (Priyanka)",
            "givenName": "Priyanka",
            "nickname": "AB03XY",
            "mobilePhone": null,
        },
        {
            "@odata.type": "#microsoft.graph.user",
            "id": "xxxxxx",
            "deletedDateTime": null,
            "accountEnabled": true,
            "ageGroup": null,
            "displayName": "Das,  (Abhirup)",
            "givenName": "Abhirup",
            "nickname": "TU67IU",
            "mobilePhone": null,
        },
]
}
 
 
}
 
 
If we change, WebUser variable to SelectBox then I am getting values returned from Scripts. But if I change it to ListCollector it is always showing me the values from sys_user table only.
2 REPLIES 2

anshul_goyal
Kilo Sage

@AbhirupD,

A List Collector is a type of reference variable that stores comma-separated SysIDs. Based on the logic in your scripts, you're retrieving displayName and nickname attributes. However, for this to work correctly, the corresponding name or nickname values must exist in your User table.

These values are essential because they help resolve the actual SysIDs of the user records. Only once you've obtained the correct SysIDs can you apply filters and display the desired records in the List Collector variable.

Please mark my response as Accepted and Helpful for future references.

Thanks

Ankur Bawiskar
Tera Patron
Tera Patron

@AbhirupD 

list collector is variable which refers to some table.

Please discuss with your customer about the correct requirement.

If list collector is referring to sys_user then you should set sysId of those users in onChange client script.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader