- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday - last edited Friday
Hey!
In a record producer I have a custom variable of type attachment called 'bifoga_fil':
So I want to copy this to the OOTB attachment on the record producer in the back-end, so that the attachment is visible in the banner above and in the logs.
I've marked what I mean with red.
So, I am thinking an after insert business rule of some kind? What would that look like?
I'm thankful for your help.
All good,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
the file should get attached to the record if you used the record producer script
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
@ronro2 Perfect
Since you've now mapped the variable to u_attached_file on the Incident table
(function executeRule(current, previous) {
// Get the attachment sys_id from the new field
var attachmentId = current.u_attached_file;
if (!attachmentId) {
return;
}
// Get the source attachment
var sourceAttach = new GlideRecord('sys_attachment');
if (!sourceAttach.get(attachmentId)) {
return;
}
// Create new attachment on the Incident record
var newAttach = new GlideRecord('sys_attachment');
newAttach.initialize();
newAttach.table_name = current.getTableName();
newAttach.table_sys_id = current.getUniqueValue();
newAttach.file_name = sourceAttach.file_name;
newAttach.content_type = sourceAttach.content_type;
newAttach.size_bytes = sourceAttach.size_bytes;
var newId = newAttach.insert();
// Copy the file data
var sourceDoc = new GlideRecord('sys_attachment_doc');
sourceDoc.addQuery('sys_attachment', attachmentId);
sourceDoc.query();
while (sourceDoc.next()) {
var newDoc = new GlideRecord('sys_attachment_doc');
newDoc.initialize();
newDoc.sys_attachment = newId;
newDoc.data = sourceDoc.data;
newDoc.insert();
}
// Optional: Clear the field so it doesn't stay as a reference
// current.u_attached_file = '';
// current.update();
})(current, previous);
Business Rule setup :
When: After
Insert: Checked
Condition: current.u_attached_file != null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
@pr8172510 I get these two error messages:
- "Read operation against 'sys_attachment_doc' from scope 'x_vgll_rail' has been refused due to the table's cross-scope access policy"
So the business rule, and the target table are in a scoped application, and not in the Global one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
but why not use OOTB attachment type variable and let user upload file to it
Then add this script in record producer script to copy file to target record
new global.VariableUtil().copyAttachment(producer.<variableName>,'<tableName>', current.sys_id);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
@Ankur Bawiskar Because it is needed to be obligatory in some scenarios (the upload file variable), depending on choices in the record producer.
You understand me?
So if this is anything, then attachment becomes mandatory, like in the picture:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
you can use catalog UI policy/catalog client script to make attachment variable mandatory based on your condition
what's the challenge?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
