Mobile Application - Attachment adding to related Table

KeerthiPraV
Tera Contributor

I have A field for Attachment in input form.

if I add any attachment to that attachment field, it should Add that attachment to sys_attachment and related table too.
How can I configure it.
Please help me out.

1 ACCEPTED SOLUTION

Sanjay191
Kilo Patron

Hi @KeerthiPraV 

If you want to attach a file from an input form , you must use scripting. Direct field mapping does not work for attachments.

This is because attachments are stored in the sys_attachment table, so you need to explicitly add them using the Attachment API.

  1. Create an Action Item with Type = Script.

  2. Write a script inside the action to handle the attachment logic.

  3. Use the  addAttachment()method to attach the file to the required target record.
  • You have an attachment input field in the form

  • You want to attach that file to a specific record (for example, a Change or Incident)

 

 
actionResult.addAttachment( "attachment_input_field", // Name of the attachment input field "change_request", // Target table name sys_id // Sys_id of the record where attachment should be added(target record) );

Using this approach ensures the attachment is correctly added to sys_attachment and linked to the intended record.

Also you can refer the below article 
https://www.servicenow.com/docs/r/mobile/parameter-screen-var-attr.html


If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You

 

View solution in original post

2 REPLIES 2

Sanjay191
Kilo Patron

Hi @KeerthiPraV 

If you want to attach a file from an input form , you must use scripting. Direct field mapping does not work for attachments.

This is because attachments are stored in the sys_attachment table, so you need to explicitly add them using the Attachment API.

  1. Create an Action Item with Type = Script.

  2. Write a script inside the action to handle the attachment logic.

  3. Use the  addAttachment()method to attach the file to the required target record.
  • You have an attachment input field in the form

  • You want to attach that file to a specific record (for example, a Change or Incident)

 

 
actionResult.addAttachment( "attachment_input_field", // Name of the attachment input field "change_request", // Target table name sys_id // Sys_id of the record where attachment should be added(target record) );

Using this approach ensures the attachment is correctly added to sys_attachment and linked to the intended record.

Also you can refer the below article 
https://www.servicenow.com/docs/r/mobile/parameter-screen-var-attr.html


If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You

 

Thank you for Your Guidance. 
It helped me lot.
Can we set the Limit to the attachments that we are adding to the input form?