How to add dynamic values to list collector from api response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 02:51 AM
Hi all,
We have a requirement where we have to select more than one item (multi select).
Multiselect is only possible through List collector, however the problem is data is dynamically populated through json response.
So the question is how can we dynamically populate data in List collector through api/ json response, is this possible or not?
Do we have any type like list collector to achieve the above workflow?
If soo can some give a working example to demonstrate this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 07:29 AM
Hi @Aishwarya NG1
can you share to any sample JSON data? and in that which data do you want to set into the list type field?
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 07:56 PM
Hi Murthy Ch,
json data:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 08:28 PM
If the network name is referring to the correct table, you can use below logic to set the values in list collector.
var arr=[];
var obj=[{"networkId":2511,"networkName":"joanna.pilfer"},{"networkId":2510,"networkName":"Murthy"},{"networkId":2509,"networkName":"walkup"}];
gs.info(JSON.stringify(obj,null,4));
for(var i=0;i<obj.length;i++)
{
arr.push(obj[i].networkName); //pushing the networkname values. in my case i have used user names
}
gs.info(arr);
var grU=new GlideRecord("sys_user"); //gliding to user table to get the sys_id's
grU.addQuery("user_name" ,"IN", arr.toString());
grU.query();
gs.info(grU.getRowCount());
while(grU.next())
{
var grP=new GlideRecord("u_personal_table"); //your table where you want to update
grP.addQuery("sys_id","fa584b181bb7c594558d639bbc4bcbd3"); //taken specific record in my case
grP.query();
if(grP.next())
{
grP.u_list_user= grP.u_list_user+ "," +grU.getUniqueValue(); //setting with sys_id in list collector.
grP.update(); //updating the field
}
}
Hope it helps:)
You can above logic above code as a reference and implement your code.
(=tested)
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 08:38 PM
Hi @Murthy Ch ,
We are not using any table as a reference to store the json response. The objective is to directly display the Json response in the available list collector field without referring to any table.
Do we have any type like list collector to achieve the above workflow?
Thanks,
Aishwarya