Get value of attachment from Record producer in record producer script

Utpal Dutta
Tera Guru

Hi community members,

I'm working on a record producer where I need to get value of "Attachment" in my record producer script.

UtpalDutta_0-1753164768441.png

 

I need this because I'm aboring action of record producer and inserting that record somewhere else. When I'm inserting that record I need the attachment which is added by the user in Record producer to be attached in that record.

 

Any ideas or suggestions are helpful.

 

Thanks

 

1 ACCEPTED SOLUTION

Not applicable

Hi @Utpal Dutta,

 

step1: Open your record producer

specify record producer if you are working on (eg.issue management- Record Producer)

 

step2. add the script to the Record producer

Here is the script to copy attachments in Record Producer

var newRec = new GlideRecord 'incident);//or any other table
newRec.short-description = 'created from Record producer';
newRec.description ='This record was created through a producer';
newRec.insert();


//Now copy attachments from the record producer to the new record

var sa - new GlideSysAttachment();
sa.copy('sc_item_produced_record',current.sys_id,newRec.getTableName(), newRec.sys_id);
//adjust source table name in teh .copy() line if needed

 

use 'sc_item_produced_record' if the attachement is saved there

 

step3: save the Record Producer

 

Testing:

1.Service catalog-> record producer and fill the form and attach a file -> submit

 2. go to the target table (eg.incident in this example )

3. open a new record and check if the attachment is present.

 

Please mark as Correct Answer/Helpful, if applicable.

ServiceNow Developer

View solution in original post

8 REPLIES 8

Not applicable

Hi @Utpal Dutta,

 

step1: Open your record producer

specify record producer if you are working on (eg.issue management- Record Producer)

 

step2. add the script to the Record producer

Here is the script to copy attachments in Record Producer

var newRec = new GlideRecord 'incident);//or any other table
newRec.short-description = 'created from Record producer';
newRec.description ='This record was created through a producer';
newRec.insert();


//Now copy attachments from the record producer to the new record

var sa - new GlideSysAttachment();
sa.copy('sc_item_produced_record',current.sys_id,newRec.getTableName(), newRec.sys_id);
//adjust source table name in teh .copy() line if needed

 

use 'sc_item_produced_record' if the attachement is saved there

 

step3: save the Record Producer

 

Testing:

1.Service catalog-> record producer and fill the form and attach a file -> submit

 2. go to the target table (eg.incident in this example )

3. open a new record and check if the attachment is present.

 

Please mark as Correct Answer/Helpful, if applicable.

ServiceNow Developer

Thanks, this worked for me but I had to first identify to which table my attachment was attaching to when I add it on the catalog item form. It seems like it is same as record producer's table. 

Since I have my record producer on Incident table I ran your script something like below.

 

var sa - new GlideSysAttachment();
sa.copy('incident',current.sys_id,'request', 'SYSID of Request');

 

Thanks again for helping me out here.

@Utpal Dutta 

You didn't share your business requirement though.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hey Ankur,

Sorry couldn't reply you earlier. It is related to a requirement for which I already posted a community question . You can find it here.

Basically we don't need record producer to insert a record in table. We are creating a request with RITMs using cart with this record producer.

I wanted to capture attachment which is added to record producer and populate it in Request which Record producer has created.

 

I hope it helps in understanding the requirement.