- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2024 01:19 AM
Hi, i have a requirement to create a project when a demand is approved. also all attachments should be copied from demand to project. i am thinking to create a business rule with gr.initialize but i dont know how to copy attachments. can someone give me what should be the code to create project and copy attachments.
thanks,
sry
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2024 06:52 AM
Almost. This is more what I was suggesting:
var gr = new GlideRecord('pm_project');
gr.initialize();
gr.field_1=current.field_1;
gr.field_2=current.field_2;
....
....
var project_sys_id = gr.insert();
GlideSysAttachment.copy('dmn_demand', current.sys_id, 'pm_project', project_sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2024 04:26 AM
The Business Rule with a script that contains .initialize() or .newrecord() is the right approach. Just set the value of whatever fields on the project record from the demand record or whatever, ending with something like this:
var project_sys_id = projectGR.insert();
where projectGR is the GlideRecord you instantiated to create the project record. Following this, you can use the copy attachment API:
GlideSysAttachment.copy('dmn_demand', current.sys_id, 'pm_project', project_sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2024 05:03 AM
Hi Brad, thank you very much for your prompt reply. is the below code correct?
var gr = new GlideRecord('pm_project');
gr.initialize();
gr.field_1=current.field_1;
gr.field_2=current.field_2;
....
....
gr.insert();
GlideSysAttachment.copy('dmn_demand',current.sys_id,'pm_project',gr.insert());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2024 06:52 AM
Almost. This is more what I was suggesting:
var gr = new GlideRecord('pm_project');
gr.initialize();
gr.field_1=current.field_1;
gr.field_2=current.field_2;
....
....
var project_sys_id = gr.insert();
GlideSysAttachment.copy('dmn_demand', current.sys_id, 'pm_project', project_sys_id);