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 10:26 AM
what type of field is it from.. what type of field is it going to...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 10:51 AM
They're both 'List' type fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 10:58 AM
Please use below in your business rule on idea table
(function executeRule(current, previous /*null when async*/) {
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();
}
}
// Add your code here
})(current, previous);
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 11:24 AM
So here's what I have, but right now I'm only getting the last entry in the array coming over (original has 'North America, Europe', the new Project record only has 'Europe').
var reg = current.u_region.getDisplayValue();
var regarray = reg.split(",");
for (var i=0; i < regarray.length; i++) {
var gotreg = regarray[i];
}
var projTable = "pm_project";
if(GlidePluginManager.isActive('com.snc.project_management_v3')){
projTable = SNC.PPMConfig.getProjectTable(current.getTableName());
}
var proj = new GlideRecord(projTable);
proj.setValue("u_regions", gotreg);
var dmnId = proj.insert();
proj.get(dmnId);
current.proj = dmnId;
//current.stage = 'demand';
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-24-2017 12:17 PM
I think we were overthinking this, simply doing this works :
var reg = current.u_region.getDisplayValue();
var projTable = "pm_project";
if(GlidePluginManager.isActive('com.snc.project_management_v3')){
projTable = SNC.PPMConfig.getProjectTable(current.getTableName());
}
var proj = new GlideRecord(projTable);
proj.setValue("u_regions", reg);
var dmnId = proj.insert();
proj.get(dmnId);
current.proj = dmnId;
//current.stage = 'demand';
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);
