Make the Attachment variable used in the catalog item add the file to the top of case as when using the paper clip

Gabriel Alowa
Giga Contributor

Recently Servicenow added a new variable type named attachment and it works great. Here is my question. When that variable is used on the catalog item , it attaches the file in the work note in the case created. That location is different from where the files is attached when using the paper clip . Is here a way to make the new variable attachment add the file to the top of the case as when you use the paper clip? 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Gabriel Alowa 

I have shared working solution in this link below

Disable ZZ_YY prefix from attachment when added through record producer

Adding the same here for your reference:

1) I created Async After Insert BR on the sc_req_item table

2) Script as this

a) Remove the ZZ_YY

b) Then use the Copy Attachment functionality

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord("sys_attachment");
	gr.addQuery("table_name", "ZZ_YY" + current.getTableName());
	gr.addQuery("table_sys_id", current.sys_id);
	gr.query();
	if (gr.next()) {
		gr.table_name = current.getTableName();
		gr.update();
		new global.VariableUtil().copy(gr.sys_id, current.getTableName(), current.sys_id); 
	}

})(current, previous);

Regards
Ankur

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

View solution in original post

17 REPLIES 17

Are you using the native UI, Service Portal, or both? Do you have a script to make the variable mandatory under these conditions?

I am using both , I have created catalog UI policy with the catalog UI poly actions to make the variable mandatory . I want to say that I like the look of the new attachment variable but not sure how to properly use the script you provided me with. What table to use.

var attach = new GlideRecord('sys_attachment');        attach.addQuery('table_name', 'ZZ_YYsc_req_item');        attach.addQuery('table_sys_id', current.sys_id);        attach.query();        while(attach.next()){               attach.table_name = 'sc_req_item';               attach.update();

 

Thank you for your help on this

This will run after your request form is submitted, and after the RITM has been created, so it runs on the sc_req_item table

find_real_file.png

I have an onSubmit Catalog Client script that works well in the native UI.  It calls a GlideAjax Script Include, then prevents submission if there is not an attachment, so you could apply your criteria to that, but there are different issues with the Service Portal.  Nothing insurmountable, but it sounds like it's best to use the Business Rule in your case, and hit me up later if you decide to go back to the paper clip icon.

Ankur Bawiskar
Tera Patron
Tera Patron

@Gabriel Alowa 

I have shared working solution in this link below

Disable ZZ_YY prefix from attachment when added through record producer

Adding the same here for your reference:

1) I created Async After Insert BR on the sc_req_item table

2) Script as this

a) Remove the ZZ_YY

b) Then use the Copy Attachment functionality

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord("sys_attachment");
	gr.addQuery("table_name", "ZZ_YY" + current.getTableName());
	gr.addQuery("table_sys_id", current.sys_id);
	gr.query();
	if (gr.next()) {
		gr.table_name = current.getTableName();
		gr.update();
		new global.VariableUtil().copy(gr.sys_id, current.getTableName(), current.sys_id); 
	}

})(current, previous);

Regards
Ankur

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

hello ankur,

 

i have the same query related to attachment variable. The attachment is getting downloaded by admin and not by any ITIL User. Is there any possible troubleshooting i can do to find the cause. I have posted one question also.

Re: Attachment not able to download from RITM - ServiceNow Community