How can we assign tag using scripting in servicenow?

ishaanvohra
Kilo Contributor

Hi,

I have a approval table in which all the requests for approval will appear.I have added the tags field in the approval list view from list layout.I want to add the tags in that field by using the scripting.

Is it possible to assign the tags by using script?

If it is possible then can you please tell me the scripted approach of how to do it?

6 REPLIES 6

Hello Ishaan,



May i know the status of this thread?


Let me know if that answered your question. If so, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



How To Mark Answers Correct From Community Inbox


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

tonygresko
Tera Contributor

I haven't found much on a solution so i decided to figure it out myself and wanted to share it here:

 

In our case we needed to add a predefined tag to a demand from a record producer. I found out that tags are stored in "label.list" and tag to record relationships are stored in "label_entry.list". So i added a tag to a demand from the list view of demands and went and looked at the tag to see what the insert looked like on the "label_entry.list" record. Thats where i came up with the following fields and values that needed to be filled in and inserted into the table. After it ran i went and looked in the list view for demands and saw that the one demand that came in from the record producer, had the tag on it.

Javascript i added to the record producer script:

var labelEntry = new GlideRecord('label_entry');
labelEntry.initialize();
labelEntry.title = 'Demand - ' + current.short_description;
labelEntry.table = 'dmn_demand';
labelEntry.label = <sys_id of predefined tag>;
labelEntry.url = 'dmn_demand.do?sys_id=' + current.sys_id + '&sysparm_view=';
labelEntry.table_key = current.sys_id;
labelEntry.read = 'yes';
labelEntry.insert();