- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2024 11:04 PM
Hello Team,
When the incident state changes to OnHold, am automatically attaching a file to incident record through below script.
File is getting attached but no content is available in the file.
Below is the code.
(function executeRule(current, previous /*null when async*/) {
// Fetch the JSON file content or retrieve it from a known location
var jsonContent = '{ "example": "content" }'; // Replace with your actual JSON content or file retrieval logic
// Create a new attachment record
var attachment = new GlideRecord('sys_attachment');
attachment.initialize();
attachment.table_name = current.getTableName(); // Get the table name where the deal record resides
attachment.file_name = 'example.json'; // Replace with the desired file name
attachment.content_type = 'application/json';
attachment.table_sys_id = current.sys_id; // Get the sys_id of the deal record
attachment.data = jsonContent; // Set the JSON content
attachment.insert();
})(current, previous);
Thanks,
Srinidhi Munji.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 02:52 AM
@srinidhi Please update your business rule script as follows.
(function executeRule(current, previous /*null when async*/) {
// Fetch the JSON file content or retrieve it from a known location
var jsonContent = '{ "example": "content" }'; // Replace with your actual JSON content or file retrieval logic
var attachment = new GlideSysAttachment();
var contentType = 'application/json';
var agr = attachment.write(current, 'example.json', contentType, jsonContent);
})(current, previous);
Please mark the answer helpful and correct if it manages to address your issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 03:20 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 02:52 AM
@srinidhi Please update your business rule script as follows.
(function executeRule(current, previous /*null when async*/) {
// Fetch the JSON file content or retrieve it from a known location
var jsonContent = '{ "example": "content" }'; // Replace with your actual JSON content or file retrieval logic
var attachment = new GlideSysAttachment();
var contentType = 'application/json';
var agr = attachment.write(current, 'example.json', contentType, jsonContent);
})(current, previous);
Please mark the answer helpful and correct if it manages to address your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 03:19 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 03:20 AM
Tested this on my dev instance and it works perfectly for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 10:28 PM