How to pass the attachment from record producer to target record when we updating the target record?

Vijaya13
Tera Contributor

I have created the record producer to update the Pre-Contract record. I'm using below script to update the target record. But I have noticed that attachments updated in the record producer are not copying to the target record. So, how can I pass the attachments from record producer to target record?

var record = producer.number;
var review = new GlideRecord('x_pgpl2_spend_pre_contract_task');
review.addQuery('sys_id', record);
review.addQuery('pre_contract_task_type', 'legal_summary');
review.addQuery('active', true);
review.query();
//if we find a record update it
if (review.next()) {
    review.key_services = producer.key_services;
    review.governing_law = producer.governing_law;
    review.key_legal_risk = producer.key_legal_risk;
    review.what_mitigation_are_in_place_for_covid = producer.what_mitigation_are_in_place_for_covid;
    review.manuscript_page_date_signature = producer.manuscript_page_date_signature;
    review.sanctioned_countries = producer.sanctioned_countries;
    review.state = "3";
    GlideSysAttachment.copy('sc_cat_item_producer', '8fec032b87f895906be8a9383cbb3589', 'x_pgpl2_spend_pre_contract_task', review.sys_id);
    review.update();
    current.setAbortAction(true);
    gs.addInfoMessage("Thanks for providing the Legal Summary");
    //    producer.portal_redirect ="esc?id=ec_dashboard";

} else {


    gs.addInfoMessage("Legal Summary has already provided");
    current.setAbortAction(true);
    //    producer.portal_redirect ="?id=ec_dashboard";
}

4 REPLIES 4

AishwaryaShukla
Kilo Guru
Kilo Guru

Hi @Vijaya13 ,

The attachments are not stored in the record producer table. The attachments are attached on the record which the record producer creates.
For eg. if your record producer is on 'incident' table, then the attachments will be found at the incident record which gets created on the submission of record producer.

So, in your case you need to replace in the 'sc_cat_item_producer' table, with the table name on which the record producer is set. And then provide the appropriate source sys_id.

NOTE: The GlideSysAttachment API is no longer supported by ServiceNow. Although it works, you will not get any support from ServiceNow if needed.
I would suggest using other ways to achieve this. For example, you can directly glide on the 'sys_attachment' table, query the required attachment, and then insert the same attachment in the 'sys_attachment' table, against the desired record.

Hope this resolves your issue. Do let me know if you have further doubts.
Mark this answer as correct/helpful so that others, with similar queries, can benefit from it.

Thanks,
Aishwarya

Hi Aishwarya,

We have created one variable on record producer as "Attachment" type to attach the document. Documents are passing to target record but its showing on notes section only, not on the top of the record (attachment bar).
So, we have written script on Record producer as mentioned below. But new attachment do not have data, its showing blank. What could be the issue? please suggest.


var gr = new GlideRecord('sys_attachment');
if(gr.get(producer.attachment)){
gr.table_name='idea';
gr.table_sys_id=current.sys_id;
gr.insert();

H_9
Giga Guru

Hi Vijaya,

You dont need to create a script to copy the attachments to the target tables. This is OOTB that all the attachments from record producer get added to the target record. 

On your instance you may not have the read access to the attachments. I recommend you to check the read type acls on sys_attachment table. there may be some acl preventing you from reading the attachments.

 

Once you attach an attachment to the record producer and submit it, it creates a record in sys_attachment table.

You can put the sys_id of your target record in "Table sys ID" column to see your attachment.

H_9_0-1664941787556.png

 

if any acl is restricting you from viewing the attachments then when you check the attachment table, you may see a system message as some records are removed due to security constraint.

 

Hope this explanation helps you.

Please mark the answer correct if it helps. 🙂

Thanks. 🙂

Except there are cases where you may need a script in the RP which creates a record in different tables, depending on a choice in a variable. If your final ticket is for a different table than the RP is set for, then your script needs to copy the attachments from "current" onto the new record that you created. That is the case which brought me to this article.