How do I copy one array (i.e. List) to another in a business rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 08:51 AM
I need to copy an array (List) from the Idea table to a new Project record that has another field setup exactly the same way. A straight-up 'setValue' doesn't work.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 12:19 PM
Glad it works for you.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 12:38 PM
I spoke too soon, all that was doing was dumping invalid String entries into the Project field...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 12:56 PM
ok a glide list is just a comma separated list of sys id's... so the first thing you want to do is go to the source record.. where you have the regions listed.. right click the header and make VERY sure it is a comma separated list of sys id's
now for the loop to load it.. the other poster was very close with...
var proj = new GlideRecord('pm_project');
proj.addQuery('u_idea',current.sys_id);
proj.query();
while(proj.next()){
var list = current.u_users.getDisplayValue();
var array = list.split(",");
for (var i=0; i < array.length; i++) {
//gs.print("Reference value is: " + array[i]);
proj.watch_list = proj.watch_list + array[i];
proj.update();
}
}
the only real issue with this is that there is no comma seperation...
so modify just a tad.
var proj = new GlideRecord('pm_project');
proj.addQuery('u_idea',current.sys_id);
proj.query();
while(proj.next()){
var tag = true;
var list = current.u_users.getDisplayValue();
var array = list.split(",");
for (var i=0; i < array.length; i++) {
if(tag){
proj.watch_list = proj.watch_list + array[i];
}
else{
//gs.print("Reference value is: " + array[i]);
proj.watch_list = ',' + proj.watch_list + array[i];
}
}
proj.update();
gs.addInfoMessage('final list is ' + proj.watch_list);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2017 07:55 AM
Had to modify that for my use, and not getting the expected results:
This from the current record:
Copies to the new Project like this:
Here's my BR code (your addition on bold😞
var projTable = "pm_project";
if(GlidePluginManager.isActive('com.snc.project_management_v3')){
projTable = SNC.PPMConfig.getProjectTable(current.getTableName());
}
var proj = new GlideRecord(projTable);
var tag = true;
var list = current.u_region.getDisplayValue();
var array = list.split(",");
for (var i=0; i < array.length; i++) {
if(tag){
proj.u_regions = proj.u_regions + array[i];
}
else{
//gs.print("Reference value is: " + array[i]);
proj.u_regions = ',' + proj.u_regions + array[i];
}
}
//proj.setValue("u_regions", reg);
var dmnId = proj.insert();
proj.get(dmnId);
current.proj = dmnId;
var link = ' <a href ="/' + projTable + '.do?sysparm_query=number%3D' + proj.getValue('number') + '">'+ proj.getValue('number') +'</a>';
var message = gs.getMessage("Project {0} has been created");
message = message.replace("{0}", link);
gs.addInfoMessage(message);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2017 01:46 PM
Still looking for a solution if anyone has one to offer up!
