- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 12:26 PM
Hello,
I have utilized this post to try to get my issue resolved, but figured I may get more exposure if I just post the question.
Solved: Re: Flow designer inline script issue for updating... - Page 2 - ServiceNow Community
I have a flow that I am using to update a Demand record and move it through some of its lifecycle using automation.
We have a need to add the Requested for (a custom field on the demand table) and the Requested for's manager to the Collaborators field. This is to allow them to have visibility of the Demand via the Employee Portal and for the manager to see the Demand details within the Approval record.
I have flow variables defined to use to retrieve the Sys Id's of these two user accounts and the Demand record.
I can successfully update the collaborators field with one sys Id using either of these inline scripts:
return fd_data.flow_var.requested_for_sys_id;
or
return fd_data.flow_var.manager_sys_id;
In Step 3 of my flow, I am updating the collaborators field with the requested for's name via the first script above. However, my problem is if the Demand requires a Manager approval, I need to update the collaborators field by adding the manager_sys_id to the field, this would be step 5 in my flow.
This is the inline script I am testing with. It is reading the collaborators field to get its current value, but when it updates the field it is updating it with the sys Id's of the user records and the names are not resolving. (Screenshot below).
var demandSysId = fd_data.flow_var.demand_sys_id;
var managerSysId = fd_data.flow_var.manager_sys_id;
gs.info("COLLAB1: Demand sys_id: " + demandSysId);
gs.info("COLLAB2: Manager sys_id: " + managerSysId);
var grDemand = new GlideRecord('dmn_demand');
if (grDemand.get(demandSysId)) {
gs.info("COLLAB3: Demand record found.");
var currentCollaborators = grDemand.getValue ('collaborators'); //this is working
gs.info("COLLAB4: currentCollaborators: " + currentCollaborators);
var collaboratorsArray = currentCollaborators ? currentCollaborators.split(',') : [];
//Check is managerSysId is already in the list
if (!collaboratorsArray.includes(managerSysId)) {
gs.info("COLLAB5: Adding managerSysId to list.");
collaboratorsArray.push(managerSysId);
} else {
gs.info("COLLAB6: managerSysId already exists.");
}
gs.info("COLLAB7: REturning updatd list: " + JSON.stringify(collaboratorsArray));
return collaboratorsArray;
} else {
gs.info("COLLAB8: Demand record NOT found.");
return[];
}
Screenshot of the updated Collaborators field:
These are valid sys Id's of the users that should be added.
Thoughts or suggestions on what I am doing wrong and how I can fix it?
Regards,
Jeremy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 08:25 PM
Collaborators is a list collector field, so you should pass the string value.
In your script, I can see that you are returning an array of sys_ids. Please update your return statement as follows:
return collaboratorsArray.toString();
Updated script:
var demandSysId = fd_data.flow_var.demand_sys_id;
var managerSysId = fd_data.flow_var.manager_sys_id;
gs.info("COLLAB1: Demand sys_id: " + demandSysId);
gs.info("COLLAB2: Manager sys_id: " + managerSysId);
var grDemand = new GlideRecord('dmn_demand');
if (grDemand.get(demandSysId)) {
gs.info("COLLAB3: Demand record found.");
var currentCollaborators = grDemand.getValue('collaborators'); //this is working
gs.info("COLLAB4: currentCollaborators: " + currentCollaborators);
var collaboratorsArray = currentCollaborators ? currentCollaborators.split(',') : [];
//Check is managerSysId is already in the list
if (!collaboratorsArray.includes(managerSysId)) {
gs.info("COLLAB5: Adding managerSysId to list.");
collaboratorsArray.push(managerSysId);
} else {
gs.info("COLLAB6: managerSysId already exists.");
}
gs.info("COLLAB7: REturning updatd list: " + JSON.stringify(collaboratorsArray));
return collaboratorsArray.toString();
} else {
gs.info("COLLAB8: Demand record NOT found.");
return;
}
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 08:57 PM
you are setting array as an object, but you need to set that as string
return collaboratorsArray.join(',');
// OR
return collaboratorsArray.toString();
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-13-2025 08:25 PM
Collaborators is a list collector field, so you should pass the string value.
In your script, I can see that you are returning an array of sys_ids. Please update your return statement as follows:
return collaboratorsArray.toString();
Updated script:
var demandSysId = fd_data.flow_var.demand_sys_id;
var managerSysId = fd_data.flow_var.manager_sys_id;
gs.info("COLLAB1: Demand sys_id: " + demandSysId);
gs.info("COLLAB2: Manager sys_id: " + managerSysId);
var grDemand = new GlideRecord('dmn_demand');
if (grDemand.get(demandSysId)) {
gs.info("COLLAB3: Demand record found.");
var currentCollaborators = grDemand.getValue('collaborators'); //this is working
gs.info("COLLAB4: currentCollaborators: " + currentCollaborators);
var collaboratorsArray = currentCollaborators ? currentCollaborators.split(',') : [];
//Check is managerSysId is already in the list
if (!collaboratorsArray.includes(managerSysId)) {
gs.info("COLLAB5: Adding managerSysId to list.");
collaboratorsArray.push(managerSysId);
} else {
gs.info("COLLAB6: managerSysId already exists.");
}
gs.info("COLLAB7: REturning updatd list: " + JSON.stringify(collaboratorsArray));
return collaboratorsArray.toString();
} else {
gs.info("COLLAB8: Demand record NOT found.");
return;
}
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 08:57 PM
you are setting array as an object, but you need to set that as string
return collaboratorsArray.join(',');
// OR
return collaboratorsArray.toString();
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-14-2025 04:33 AM
Thank you both! The updated code worked using:
return collaboratorsArray.toString();
Kind Regards,
Jeremy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 04:45 AM
@JeremyHoffman No problem