Demand to Project

sry
Giga Guru

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

1 ACCEPTED SOLUTION

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);

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

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);

https://docs.servicenow.com/bundle/washingtondc-api-reference/page/app-store/dev_portal/API_referenc... 

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());

 

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);