- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2016 09:46 AM
When an Idea is "Accepted", a DMND record is created using the BR "Create Demand on Accepting Idea".
I have customized the BR to copy over some field information, and would also like to copy over the attachments. Here is my script, but it's not copying over the attachments.
Any help is much appreciated!
Here is the current state of the BR, the attachment copy code is on line 6:
var demandTable = "dmn_demand";
if(GlidePluginManager.isActive('com.snc.project_management_v3')){
demandTable = SNC.PPMConfig.getDemandTable(current.getTableName());
}
var demand = new GlideRecord(demandTable);
GlideSysAttachment.copy('idea', 'f1fda4876f2c2a807cecde7c5d3ee4ad', 'dmn_demand', '0afda4876f2c2a807cecde7c5d3ee4de');
demand.setValue("state", "2");
demand.setValue("business_case", current.business_case);
demand.setValue("u_business_goals_and_objectives", current.u_business_goals_and_objectives);
demand.setValue("short_description", current.short_description);
demand.setValue("category","strategic");
demand.setValue("type", "project");
demand.setValue("submitter", current.submitter);
demand.setValue("parent", current.sys_id);
demand.setValue("idea", current.sys_id);
demand.setValue("assignment_group", current.assignment_group);
var dmnId = demand.insert();
demand.get(dmnId);
current.demand = dmnId;
current.stage = 'demand';
var link = ' <a href ="/' + demandTable + '.do?sysparm_query=number%3D' + demand.getValue('number') + '">'+ demand.getValue('number') +'</a>';
var message = gs.getMessage("Demand {0} has been created");
message = message.replace("{0}", link);
gs.addInfoMessage(message);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2016 09:52 AM
I beleive you issue is the parameters being passed into the copy attachment call. I changed it to line 20 and you can see how i am leveraging dynamic values based on you other code. Give it a try and let me know.
var demandTable = "dmn_demand";
if(GlidePluginManager.isActive('com.snc.project_management_v3')){
demandTable = SNC.PPMConfig.getDemandTable(current.getTableName());
}
var demand = new GlideRecord(demandTable);
demand.setValue("state", "2");
demand.setValue("business_case", current.business_case);
demand.setValue("u_business_goals_and_objectives", current.u_business_goals_and_objectives);
demand.setValue("short_description", current.short_description);
demand.setValue("category","strategic");
demand.setValue("type", "project");
demand.setValue("submitter", current.submitter);
demand.setValue("parent", current.sys_id);
demand.setValue("idea", current.sys_id);
demand.setValue("assignment_group", current.assignment_group);
var dmnId = demand.insert();
demand.get(dmnId);
current.demand = dmnId;
current.stage = 'demand';
GlideSysAttachment.copy('idea', current.sys_id, 'dmn_demand', demand.sys_id); // second paramenter is the current record and new record you created
var link = ' <a href ="/' + demandTable + '.do?sysparm_query=number%3D' + demand.getValue('number') + '">'+ demand.getValue('number') +'</a>';
var message = gs.getMessage("Demand {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
‎09-16-2016 09:51 AM
Hi Todd,
It looks like you've hard coded the target sys_id. You should move the copy statement bellow your demand.insert so you can use the dmnId variable.
Thanks,
Cameron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2016 09:52 AM
I beleive you issue is the parameters being passed into the copy attachment call. I changed it to line 20 and you can see how i am leveraging dynamic values based on you other code. Give it a try and let me know.
var demandTable = "dmn_demand";
if(GlidePluginManager.isActive('com.snc.project_management_v3')){
demandTable = SNC.PPMConfig.getDemandTable(current.getTableName());
}
var demand = new GlideRecord(demandTable);
demand.setValue("state", "2");
demand.setValue("business_case", current.business_case);
demand.setValue("u_business_goals_and_objectives", current.u_business_goals_and_objectives);
demand.setValue("short_description", current.short_description);
demand.setValue("category","strategic");
demand.setValue("type", "project");
demand.setValue("submitter", current.submitter);
demand.setValue("parent", current.sys_id);
demand.setValue("idea", current.sys_id);
demand.setValue("assignment_group", current.assignment_group);
var dmnId = demand.insert();
demand.get(dmnId);
current.demand = dmnId;
current.stage = 'demand';
GlideSysAttachment.copy('idea', current.sys_id, 'dmn_demand', demand.sys_id); // second paramenter is the current record and new record you created
var link = ' <a href ="/' + demandTable + '.do?sysparm_query=number%3D' + demand.getValue('number') + '">'+ demand.getValue('number') +'</a>';
var message = gs.getMessage("Demand {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
‎09-16-2016 09:59 AM
That did it, thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 01:14 AM
To copy attachments from idea to demand:
1: Create an "after" business rule on the "demand" table when inserting a record.
with following:
(function executeRule(current, previous /*null when async*/ ) {
var demand = current.sys_id.toString();
var idea = current.idea.sys_id.toString();
GlideSysAttachment.copy('idea', idea, 'dmn_demand', demand);
current.update();
})(current, previous);
it's worth adding a condition to check if an idea exists on the current demand as you can create demands directly.