- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2021 04:59 AM
Hi All,
How i can store multiple values in one varible and join with comma , by current sys_id i am getting two sysid i want store two sys_id in one variable ?
in ui action var sys_id = current.sys_id;// getting two sys_id want to join in one variable
var arr = [];
var SYSID = arr.join(',');
gs.addInfoMessage(SYSID);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2021 10:11 PM
I am already responding on this thread.
So if you think I answered your original question of setting the number field with the list of RITMs selected then mark my response as correct and close this question.
Regards
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-12-2021 06:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2021 08:21 AM
not sure if 2 level dot walking is allowed in client side GlideRecord
Can you try this
I know this is not best practice to use GlideRecord in client script and that too 2 times
But just want to confirm
Once confirmed you can use GlideAjax with Synchronous call and call script include and get all the requested for
function sendCustomEmail() {
var sysIds = g_list.getChecked().toString();
var requested_forArray = [];
for(var i=0;i<sysIds.length;i++){
var gr = new GlideRecord("sc_req_item");
if(gr.get(sysIds[i].toString())){
var req = new GlideRecord('sc_request');
req.get(gr.request);
if(req.requested_for){
requested_forArray.push(req.requested_for.toString());
}
}
}
alert('array->'+ requested_forArray);
var url = '/sc_task.do?sys_id=-1&sysparm_query=u_number=' + sysIds + '^u_to_whom=' + requested_forArray.toString();
top.location.href = url;
}
Regards
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-12-2021 08:24 AM
Or as an alternative try this
Display business rule on sc_task
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ritms = current.u_number.toString();
var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", "IN", ritms);
gr.query();
while(gr.next()) {
arr.push(gr.request.requested_for.toString());
}
current.u_to_whom = arr.toString();
})(current, previous);
From UI Action only set the u_number
sendCustomEmail();
function sendCustomEmail() {
var sysIds = g_list.getChecked().toString();
var url = '/sc_task.do?sys_id=-1&sysparm_query=u_number=' + sysIds;
top.location.href = url;
}
Regards
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-12-2021 08:28 AM
Hi ankur ,
My seniors has guided me to to store the sysid of selected ritm in g_scratchpad
at present the field is reference in my project dev i have use that scratchpad
https://community.servicenow.com/community?id=community_question&sys_id=b5835242db0c7c106064eeb5ca96192f
Kindly guide me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2021 10:10 PM
I already mentioned the another approach i.e. using Display BR and the UI Action
Did you try that?
Also you can use this if you want scratchpad variable
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ritms = current.u_number.toString();
var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", "IN", ritms);
gr.query();
while(gr.next()) {
arr.push(gr.request.requested_for.toString());
}
g_scratchpad.users = arr.toString();
})(current, previous);
Then use onLoad client script to set the value
function onLoad(){
if(g_scratchpad.users != ''){
g_form.setValue('u_to_whom', g_scratchpad.users.toString());
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader