logo

NJP

Attachment Variable & Making Attachment Mandatory In Catalog Items With Zero Code [PARIS]

Import · Aug 27, 2020 · article

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 link : Attachment 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

image

Portal UI ( This looks better than Native UI)

image

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.

image

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

image

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.

image

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

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.

image

image

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.

image

image

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"

image

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"

image

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

View original source

https://www.servicenow.com/community/itsm-articles/attachment-variable-making-attachment-mandatory-in-catalog-items/ta-p/2301120