How to add file attachment from record producer ?

Test203
Kilo Contributor

I have a upload attachment functionality on our record producer on portal. When user uploads a file and submits the RP, we want the attachment to be added to a file attachment field in a table. Any leads as to how we achieve this.

1 ACCEPTED SOLUTION

Shubham Tipnis
Kilo Sage
Kilo Sage

Hi,

 

Since file attachment needs the sys_id of sys_attachment, you can simply assign the attachment from RP to the file attachment field like this -

gr.u_file_attachment_field = producer.upload_attachment_field; //replace the variable and field names as per your requirement.

 

Please mark correct/helpful if applicable.

 

Regards,
Shubham

Regards,
Shubham Tipnis
 ServiceNow Enthusiast
️ 3x Rising Star (2022–2024) – ServiceNow Community
 Sharing insights, use cases & real-world learnings from the Now Platform
 Always learning. Always building.

View solution in original post

2 REPLIES 2

Shubham Tipnis
Kilo Sage
Kilo Sage

Hi,

 

Since file attachment needs the sys_id of sys_attachment, you can simply assign the attachment from RP to the file attachment field like this -

gr.u_file_attachment_field = producer.upload_attachment_field; //replace the variable and field names as per your requirement.

 

Please mark correct/helpful if applicable.

 

Regards,
Shubham

Regards,
Shubham Tipnis
 ServiceNow Enthusiast
️ 3x Rising Star (2022–2024) – ServiceNow Community
 Sharing insights, use cases & real-world learnings from the Now Platform
 Always learning. Always building.

Community Alums
Not applicable

Hi,

You can use following script in record producer script section to attach the attachment to current record, you can update it accordingly 

var gr = new GlideRecord('sys_attachment');
if(gr.get(producer.attachment)){ //attachment field name
	gr.table_name='incident';     //copy to table name
	gr.table_sys_id=current.sys_id;//copy to record sys_id
	gr.insert();
	
}

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep