Add a tag to attachment via business rule

Richard Thomas
Kilo Contributor

Hi Experts,

I have business rule where I'm trying to add a tag to an attachment on insert/update. Here is my script;

function executeRule(current, previous /*null when async*/) {

var addLabelGR = new GlideRecord('label_entry');
addLabelGR.initialize();
addLabelGR.label = 'f3bc06fbdb414950611353835b96198f'; //change the sys id of the label you want.
addLabelGR.url = 'sys_attachment.do?sys_id=' + attachmentID + '&sysparm_view=';
addLabelGR.table = current.table_name;
addLabelGR.table_key = current.table_sys_id;
addLabelGR.table = sys_attachment;
addLabelGR.notify_onchange = false;
addLabelGR.read = 'yes';
addLabelGR.title = 'Attachment - ' + filename;
addLabelGR.insert();

})(current, previous);

I think in some cases it will create the label but it won't add it to the attachment

find_real_file.png

Does anyone have any experience of doing this?

Thanks as always

Richard

1 REPLY 1

Jaspal Singh
Mega Patron
Mega Patron

Yes, all it will do is create a tag. For associating it to the record you need a BR on Attachment table that will go in and update the record.