- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 07:03 AM
Hi Friends,
Please help me with my below requirement.
I have a list collector variable xyz in abc variable set. This variable refers sys_user table.
how can we map the users in xyz variable to watch_list field on RITM notes section (after submitting the request).
I guess we can create catelog client script on variable set and get the value of xyz variable and send to script include and then there we can map these value with watchlist.
I am unable to implement the code, so could someone please help me with the code.
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 08:10 AM
Thanks for the update Kumaraj. No worries. Below, please find the solution that I shared with you.
Create a Before business rule with Script as:
current.watch_list = current.variables.xyz;
Let me know if that answered your question. If so, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 07:33 AM
Is this single row or multi row variable set? For single row this can be done:
1. you can access the variable in a variable set by current.variables.variable_set.variable
so in your case e.g.
var subscribed = current.variables.abc.xyz;
this way you get sys IDs of the users in the list collector separated by commas
- I haven't tested it further but you can basically follow by:
2. fill in the watch_list
current.watch_list = subscribed;
since it uses similar format (sys IDs separated by commas) no transformation is needed
---
run scrip in your workflow is the best place to go
I have tested it on background script with a sample RITM and it works just fine
var gr = new GlideRecord('sc_req_item');
gr.get('5c752cb4db201010f16be04a489619c5');
subscribed = gr.variables.first_variable_set.my_users;
gr.watch_list = subscribed;
gr.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 01:21 AM
variable - xyz, variable set - abc
Actually I do not have to modify workflow as there are more than 50 workflow where we are using this variable set, so we can not make changes in all.
So if some way I map all the users listed in xyz variable to watch_list field on RITM and then I can add watch_list in notification(Whom to send field), then all the listed user should get the request submission email.
Now I am not sure how to access listed users in variable and the particular catelog item in below client script and how to write code in script include to map the users in watch list on RITM.
I really appreciate if some can help in achieving the above goal and way except workflow modification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 01:32 AM
Hi,
so you don't want to edit all workflows; why to have multiple catalog client script since you will have to use multiple catalog client scripts
you can have BR; before insert on sc_req_item
1) create system property which will hold array of json object ; catalog item sys_id and the variable which is list collector in that respective catalog item
Example: [{"catalogItemSysId":"sys_id1","variable":"variableA"},{{"catalogItemSysId":"sys_id2","variable":"variableB"}}]
Note: here variableA is list collector variable which belongs to catalog item whose sys id is sys_id1
2) when BR run check whether the current catalog item is present in the system property if yes then execute script to set the variable from respective catalog item
Sample script below; so going in future even if you want to allow this to run for 51st catalog item; just update the system property with 1 more json object
var propertyValue = gs.getProperty('name');
var obj = JSON.parse(propertyValue);
var currentSysId = current.cat_item;
for(var i=0;obj.length;i++){
if(obj[i].catalogItemSysId == currentSysId){
var watchListVariableName = obj[i].variable;
var variableValue = current.variables[watchListVariableName];
if(variableValue!=''){
current.watch_list = variableValue.toString();
}
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 01:44 AM
we have variable under variable set, so if some how we map users selected in variable to watch_list on RITM form then we do not need to create multiple client script for all catelog.
Variable type is List collector and refering to sys_user tabel.
can we do it using catalog client script on variable set or some way. I need it urgently, if you can suggest me the codes and step that will really help me as I tried enough from my side.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 01:52 AM
Hi Kumar,
please check below example and explain
are you saying you are having a single variable set which contains list collector variable and this variable set is used by 50 catalog items?
also catalog client script onchange or onsubmit won't work since RITM is generated only after you submit the request
So you will have to do this using single BR if you don't want to touch 50 workflows
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
