
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 12:20 AM
Hi
I have an requirement to copy all the attachments when project is get created from the demand. I am using a After BR but attachments are not getting attached to the problem which is created on approval of demand.
It would be great help if anyone help with the logic.
(function executeRule(current, previous /*null when async*/ ) {
var Projgr = new GlideRecord("pm_project");
Projgr.initialize();
var fields = ['short_description', 'primary_program', 'business_case', 'sys_domain', 'investment_class', 'investment_type', 'risk_of_performing', 'risk_of_not_performing', 'enablers', 'barriers', 'in_scope', 'out_of_scope', 'assumptions', 'goals', 'strategic_objectives', 'business_unit', 'department', 'impacted_business_units', 'business_applications', 'business_capabilities',
'cmdb_ci', 'company', 'priority', 'urgency', 'impact', 'rate_model', 'project_manager', 'project_currency', 'u_type_of_project', 'description', 'u_project_importance_for_business', 'u_launch_time_estimation', 'u_business_requirements', 'u_is_this_a_critical_project', 'u_business_analyst', 'number'];
for (var index in fields) {
var field = fields[index];
if (Projgr.isValidField(field)) {
Projgr.setValue(field, current.getValue(field));
}
}
Projgr.u_submitter = current.getDisplayValue("submitter");
Projgr.phase = "planning & executing";
var projId = Projgr.insert();
var attach = new GlideSysAttachment(); // copy attchment from demand to project
attach.copy('dmn_demand', 'current.sys_id', 'pm_project', 'projId');
gs.info("Project ID:" + projId);
var link = ' <a href ="/' + projectTable + '.do?sysparm_query=number%3D' + Projgr.getValue('number') + '">' + Projgr.getValue('number') + '</a>';
var message = gs.getMessage("Project {0} has been created");
message = message.replace("{0}", link);
gs.info("Demand ID:" + current.sys_id);
gs.info("attachment successfully attached");
gs.addInfoMessage(message);
//new GlideSysAttachment();
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 02:08 AM
you are passing wrong values in that function
use this
attach.copy('dmn_demand', current.sys_id, 'pm_project', projId);
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
09-07-2023 02:07 AM
why not use attachment related list and it will reduce the size of attachment table by not copying the same file?
check this
TNT: "Related Attachments" Related List
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
09-07-2023 02:08 AM
you are passing wrong values in that function
use this
attach.copy('dmn_demand', current.sys_id, 'pm_project', projId);
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