How to copy the attachment from table record to record producer using UI action

naveen80
Tera Contributor

Hi Experts,

 

I was trying to attach the files of incident record to record producer on click of UI button.

 

I've tried 'GlideAttachment.copy()' which helps only from record to record, but not record to form.

 

Can you please advise, how to make this work.

 

Thanks in advance..!!

 

Regards,

Naveen.

1 ACCEPTED SOLUTION

@naveen80 

do this

1) create a string variable on record producer and give it higher order

2) pass the incident record sysId from URL parameter when you redirect user to record producer

3) use onLoad catalog client script and get that URL parameter value and set it in variable and hide it

4) then use Record producer script to copy attachment

GlideSysAttachment.copy('incident', producer.variableName, 'target_table', current.sys_id);

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

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

View solution in original post

17 REPLIES 17

Samaksh Wani
Giga Sage
Giga Sage

Hello @naveen80 

 

 

you can send values from UI action through URL by adding parameters.

in the onload client script of record producer fetch values from url and populate in the record producer fields.

regarding attachment is somewhat difficult but you can try this:

1) send sys_id of the incident record in the url as parameter

2) in onload get the sys_id value

3) call GlideAjax function and send sys id of incident and sys id of the record producer

gel('sysparm_item_guid').value

4) use copy attachment functionality and copy attachment from incident record to record producer

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

naveen80
Tera Contributor

Hi Samaksh,

 

Thank you for the response..!!

 

I've tried the same approach, but 'gel('sysparm_item_guid').value' cannot be used in service portal.

I've also found the KB article  - https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0723775

 

I've tried the resolution of the KB article as well, but no luck.

 

Expectation - I was looking to fetch the record sys_id before the record gets created from the record producer. bcoz, when I add the attachment manually I can see that attachment record is generated in to the target table.

 

Let me know if there is any other approach i can work up on.

 

Hello @naveen80 

 

var item_guid = angular.element("#sc_cat_item").scope().data._attachmentGUID;

 

use above code as your reference to solve the query.

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

Hi Samaksh,

 

I was getting this error - 'There is a JavaScript error in your browser console'.

naveen80_0-1696514006394.png

can you help me with this error.

 

Thanks,

Naveen.