- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
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.
-
Create an Action Item with Type = Script.
-
Write a script inside the action to handle the attachment logic.
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
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.
-
Create an Action Item with Type = Script.
-
Write a script inside the action to handle the attachment logic.
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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?
