logo

NJP

Custom Attachment Button and Use it anywhere in the form as Attachment Formatter

Import · Oct 16, 2019 · article

Custom Attachment button and use it anywhere in the form Using UI Macro and Formatter

Create a UI Macro for an Attachment:

  1. Navigate to System UI> UI Macros.
  2. Click New.
  3. Complete the form.(name it as add_attachment)
  4. In the XMLscript field enter below Script:
<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null"> 

  <button type="button" onclick="saveAttachment(g_form.getTableName(), g_form.getUniqueValue())">Attachment</button> 

</j:jelly>

Refer below SS:

image

Create a Formatter :

  1. Navigate to System UI> Formatters.
  2. Click New.
  3. In the Namefield, enter a descriptive name for the formatter.(In our case name would be Attachment on Form)
  4. In the Formatterfield, enter the name of the UI macro with .xml appended to it. (In our case UI Macro name would be add_attachment)
  5. In the Table field, select the table in which the formatter will be used.
  6. In the Type field, select Formatter.
  7. Click Submit.

Refer below SS:

image

Yes we are done here , now lets open an Incident form layout and add our Attachment on Form formatter in a form and save it as shown below:

image

Now in an Incident form you will see the Attachment button as shown below:

image

When you will click on it , you will be having an ability to attach a file:

image

I am open for suggestions and improvement so feel free to comment on the article.

That’s all guys, if you find this article helpful please like, share and Subscribe!!

See you

Ajay

+91-9769949577

Labels:

image

View original source

https://www.servicenow.com/community/now-platform-articles/custom-attachment-button-and-use-it-anywhere-in-the-form-as/ta-p/2309585