The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Joshwa Antony S
Mega Guru

Hi All,

PARIS introduced a new variable called "Attachment" which some of you might know already, Here I would like to cover some of the key use cases and other details around this feature such as...

  • Developer capabilities/control over this variable
  • How this feature works with Notification "Include Attachments"
  • How this feature works with GlideSysAttachment.copy()
  • Places where these attachments resides after the submission
  • ATF compatibility

Lets start with basic details,  The variable lets you upload an attachment for a question of the item. After you upload the attachment, you can also download, update, and delete it. Even when fulfilling the request, you can download, update, and delete the attachment in a requested item or catalog task. You can specify restrictions for file size and extensions using the max_file_size and allowed_extensions variable attributes

If the max_file_size variable attribute is not specified, the glide.sc.variable.attachment.default_max_size system property value is considered as the upper limit for the attachment file size. The default value is 20MB

allowed_extensions - This is to enforce the type of attachment that needed for the catalog item

Docs linkAttachment Variable

Here comes the most important use case that we are seeing multiple times in multiple project, "Make the attachment mandatory for the catalog item in both Native UI and Portal UI" (OR) "Make the attachment mandatory when "XYZ" variable selected with value "ABC".

Before PARIS, we used to achieve this in multiple ways and all of them are bad practices as per ServiceNow standards.

  • onSubmit client script, GlideAjax with getXMLWait (getXMLWait not supported in portal and scoped app)
  • onSubmit client script with GlideRecord
  • onSubmit client script with DOM (document.getElementById('header_attachment_list_label');, etc..)
  • Global UI Script using angular.element and adding it as JS Include in Portal themes

So the PARIS feature is a big relief for ServiceNow (user experience and performance) and to the developers because they don't need to write any script.

  • Use the "Attachment" variable like other Service Catalog variables, there are no extra settings/configurations other than those two attributes specified above.
  • Mark the variable mandatory in variable level (or) using UI Policy Action (this is for making attachment mandatory based on condition)

So wanna see how it looks like before you try it out!

Native UI

find_real_file.png

Portal UI ( This looks better than Native UI)

find_real_file.png

 

As a developer what else we can do with this "Attachment" variable?

1. You can read the variable value using "g_form.getValue("VariableName");" and this returns "SYSID" of the attachment record [sys_attachment],
Use case: This is helpful if you want to check the file name attached by user and alert them if its not right file. We are no longer dependent on g_form.getValue("sysparm_item_guid");


2. You can auto set the attachment to the variable using "g_form.setValue("VariableName","SYSID OF ATTACHMENT");",
Use case: When you have requirement to auto attach any attachment/document based on some condition or without any condition.


3. You can also clear the value of this variable using "g_form.clearValue("VariableName");",
Use case: When you are making the attachment variable mandatory based on value "ABC", so user added the attachment then suddenly user selected different value "DEF" where you need to clear the attachment automatically to avoid unnecessary attachments in your RITM.

 

How the attachments are present in target table, (Requested Item)?

The added attachments through variable are not available in header portion(where Manage Attachment present) of the RITM record where we usually see the attachments of the record, instead its available in variable editor and "Activity Stream".

Note: The attachments are copied only to RITM, not to the catalog tasks automatically.

find_real_file.png

Activity Steam: It works along with "Filter Activity" Attachment, if you uncheck this OR if we didn't configure this in activity stream, then user will not be able to see the added attachment in RITM after submission

find_real_file.png

 

Will it works with "Include Attachments" checkbox of Notification?

No, it will not. The attachment added through the "Attachment" variable not added to the header portion (where Manage attachments present) as stated above and its not considering these attachments to be include in the notification when "Include Attachments" marked true

So, if you are having an use case where you want to ask the attachment from user and send the physical (not the link) attachment to any user, it wont be possible using "Include Attachment" checkbox.

I verified it by adding attachments in both variable and header portion (paperclip icon), the notification includes only the attachment added through paperclip icon.

find_real_file.png

Haa! its kind of introducing one feature and causing less benefits over another 😞

 

Will GlideSysAttachment.copy(); works to copy the attachment added via variable?

Yes, It will. GlideSysAttachment.copy() is a useful API so far to all and it continues to works with new Attachment Variable too.

GlideSysAttachment.copy('sc_req_item','sourceSYSID','sc_task','targetSYSID');

After copying attachments using this API, you fill find the attachments added through variable in "Activity Stream" and attachments added from paperclip icon in header portion of target record.

find_real_file.png

find_real_file.png

 

Will it support ATF (Automated Test Framewrok)?

Yes, it will.

Use Record Query step to fetch any attachment SYSID or hardcode the sys_id, then use "Set Variable Values" step to set the sys_id.

find_real_file.png

find_real_file.png

How the attachments are stored in sys_attachment table before submission?

Its same like other releases with one small difference.

In other releases, the attachments are added to "sys_attachment" table with Table Name as "sc_cart_item", but in Paris with prefix "ZZ_YY"

find_real_file.png

How the attachments are in in sys_attachment table after submission?

Its same like other releases with one small difference.

In other releases, the attachments are pushed to target table with Table Name as "sc_req_item", but in Paris with prefix "ZZ_YY"

find_real_file.png

 

Limitations

  • We can select only one attachment for a variable, if you guys have requirement to ask more than one attachment before submission then you need to create multiple "attachment" variable
  • This variable not available to Multi row variable set (MRVS)
  • Impacts performance when we are attaching large size attachment
  • Sending attachments over email using "Include Attachments" is not possible (as far as I researched)

 

That's all I have! Thanks for reading and do comment with your suggestion and points that I have missed to cover

Don't forget to Mark it Helpful, Bookmark if this helps you in anyway.

Regards,

JAS

Comments
Lieve Verhelst
Tera Expert

This will solve so many.. issues we encounter at this moment. 

Can't wait till the upgrade is done at my company!

 

Joshwa Antony S
Mega Guru

Glad, you find my article helpful. Cheers 

cherylbrownlee
Tera Contributor

This article is very helpful, thank you! Do you have any idea why ServiceNow decided to add the prefix ZZ_YY to the target table on the attachment in Paris? 

FYI - an idea has been added to remove this prefix from the attachment table so pre-Paris functionality will be restored.

View Idea Page - ServiceNow Community

ALBIN BABY
Tera Contributor

Hi,

This variable will be very helpful.

In the mobile, if i open this variable iam able to see 4 options which are:- Take photo, Record video, Open Gallery and Attach File.

I have  requirement of only allowing to upload images. Can we modify the attachment variable for the same  in the mobile ui for a specific catalog item.

 

John Palmer
Tera Expert

 

GlideSysAttachment.copy() 

didn't seem to work for me... didn't seem to copy the attachment to my Data Source record (the import/Transform failed to create any records... I didn't look at the Activity Stream- I JUST NOW noticed this:

"After copying attachments using this API, you fill find the attachments added through variable in "Activity Stream" and attachments added from paperclip icon in header portion of target record."

(I'll retest this later )

after much research, I found this:

Use the alternative new global.VariableUtil().(attachmentId, targetTable, targetId);

(adding that here to make it easier for others to find....)

.. haven't tested THIS yet either.

 

Mohammed Lais1
Mega Guru

Great Article.

 

To show attachment links in Approval Notification body, below notification email script can be used.

 

var attachmentID = [];
	var reqItem = new GlideRecord('sc_req_item');
	reqItem.get(current.sysapproval);

	if(reqItem){
		var attachVariable = new GlideRecord('item_option_new');
		attachVariable.addEncodedQuery('type=33^active=true^cat_item.sys_id='+reqItem.cat_item);
		attachVariable.query();
		while(attachVariable.next()){
			if(JSUtil.notNil(reqItem.variables[attachVariable.name]))
				attachmentID.push(reqItem.variables[attachVariable.name]);
		}

		var attachmentQuery = 'table_sys_id='+reqItem.sys_id;
		if(attachmentID.length>0)
			attachmentQuery += '^ORsys_idIN'+attachmentID.toString();
		var attachGlide = new GlideRecord('sys_attachment');
		attachGlide.addEncodedQuery(attachmentQuery); 
		attachGlide.query();
		if (attachGlide.hasNext()) {
			template.print("<b>Attachments: </b><br />");

			while (attachGlide.next()) {
				var attachLink = '<a href="' + gs.generateURL(attachGlide.getTableName(),attachGlide.sys_id) +   '">' + attachGlide.file_name + '</a>';
				template.print(attachLink +   "<br />");
			}
		}
	}

 

Attachment from multiple attachment variables and also the manual attachments uploaded to form header will be displayed.

Carlos Candano
Mega Guru

They should make the attachment variable attach the file to the record instead of just in the variable. I don't know any use cases that will not want the attachment on the created record. There's also a bug with deleting and uploading attachments again. The old attachment is not getting deleted on the sys_attachment table

cherylbrownlee
Tera Contributor

I agree! Could you please go here on the Idea Portal and comment/upvote?

View Idea Page - ServiceNow Community

Inactive_Us1969
Kilo Explorer

Hi all, is there a way of getting the antivirus scan to work like with the standard paperclip functionality? The scan does not get triggered until after the submit... Thanks

Joshwa Antony S
Mega Guru

Hello Ryon,

As per the Docs the scanning starts on submission,

"If the system-wide anti-virus check is enabled, the anti-virus check is performed on the attachment when you:

  • Submit a request for the corresponding catalog item
  • Add the catalog item to the cart or wish list"

Regards,

JAS

Joshwa Antony S
Mega Guru

Hi,

This could be because of following, taken from docs.

"When you upload an attachment to this variable, an entry is created in the Attachment [sys_attachment] table. The variable is not updated until you submit the item request, add it to the cart, or save the record while editing it (in fulfiller flows). If you delete or update the attachment before submitting the corresponding catalog item, the entry in the Attachment [sys_attachment] table is cleared"

So I assume this is to cleanup the attachments and to avoid orphan attachments.

 

Regards,

JAS

Dead Blade
Kilo Guru

We are using "onSubmit client script with DOM (document.getElementById('header_attachment_list_label');, etc..)" on our catalog items currently.  We are going through to use the Paris attachment as this article describes.  But the UI Policy is not working for mandatory if variable xyz.  The attachment is visible on load and it should not be.  We are using a standard UI Policy condition - variable is xyz = cat ui policy action - var(attachment) Mandatory true Visibility True.

But on the form submit it is not enforcing the attachment.

Has anyone else been experiencing this issue.

Inactive_Us1969
Kilo Explorer

Hi Joshwa, that is the standard functionality with most tables, but unfortunately the virus scan does not work with Attachment variables as it does with the paperclip attachment.

sekhar kurumoju
Mega Guru

Hai @Joshwa Antony Sebastian  Really it is helpful. I am using Native Ui and Portal View Script Now I am Try this. I knew how hard to mange Attachment in catalog. Thank You for sharing 

Harika22
Tera Contributor

 

@Joshwa Antony Sebastian  Thank you so much for article. Can u please let me know detailed ATF steps for same scenario. Am confused about where to use record query.

Joshwa Antony S
Mega Guru

Hi Harika,

We have to set attachment sys_id in "Set Variable values" ATF step

You can use Record query to attachment table and take any attachment from there or you can hardcode sys_id of any attachment for attachment table

example: Here "attachment" is my variable name

find_real_file.png

Hope this helps.

Regards,

JAS

Harika22
Tera Contributor

Thank you so much 🙂 it really worked @Joshwa Antony Sebastian 

reddy28
Tera Contributor

I want to upload csr file to attachment variable in the catalog form but it's not allowing to upload csr file extension. I have also added "csr" in systems properties >security but its still not allowing me to upload.

 

Any Solution for this 

Elaine Hasebe
Tera Contributor

Hello @Joshwa Antony S 

very good article!

 

How can I pass the attach variable in a payload ? 

 

And would be the API this way below???

 

https://xpto.service-now.com/api/now/attachment/file?file_name={file_name} &ZZ_YYsc_req_item=&table_sys_id={sys_id_record}

renatasanto
Tera Contributor

How to configure the Add Attachment in a catalog item to allow XSLM document?

SuryaS
Tera Contributor

Hi Guys, 
Do anyone have idea on, where do the highlighted UI action configured.

 

Screenshot_29.png

Version history
Last update:
‎08-26-2020 10:15 PM
Updated by: