Adding Visual Task Board labels to form

Soren_Bjorn_And
Tera Contributor

Hi.

When using the visual task boards you can add labels. How can I add those labels to the actual task record, so I can also see them when opening the task? I.e. SAFe features or stories? 

It is not so usefull adding a label if I can only see it on the Visual Task Board but not when I am looking at the task record itself.

Thanks in advance!

3 REPLIES 3

Rae Ann Prasnic
ServiceNow Employee
ServiceNow Employee

When you open the Story from the VTB you can see the label. Click here to view more info along with roles, etc., in case that is your issue.

find_real_file.png

If you are asking how you can add the label to the Story form itself, I do not see how to do that. I'm assuming because the label is a VTB user interface, not a Story interface. Can you use Tags to meet your requirement? 

Please mark reply as helpful or correct if applicable. Thanks! - Rae Ann

Magnus Schlamov
Giga Contributor

You can synchronize label entries between VTB cards and task records using a business rule. 

 

Table: label_entry

When to run: insert, delete

Script:

 

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


    //Synchronize label entry for task record with label entry for VTB card
    if (current.table == "vtb_card") {

        //Get VTB card record
        var sourceVtbCardRecordGr = new GlideRecord("vtb_card");
        sourceVtbCardRecordGr.get(current.table_key);

        //Get label entry for task record (if such label entry exists)
        var taskRecordLabelEntryGr = new GlideRecord("label_entry");
        taskRecordLabelEntryGr.addQuery("table_key", sourceVtbCardRecordGr.task);
        taskRecordLabelEntryGr.addQuery("label", current.label);
        taskRecordLabelEntryGr.query();


        if (current.operation() == "insert") {

            //If the current operation is insert and a label entry does not exist for the task record, create one
            if (!taskRecordLabelEntryGr.next()) {
                var targetTableName = sourceVtbCardRecordGr.task.sys_class_name;
                var targetSysId = sourceVtbCardRecordGr.task.sys_id;
                var targetClass = (function() {
                    var targetTaskGr = new GlideRecord(targetTableName);
                    targetTaskGr.get(targetSysId);
                    return targetTaskGr.getClassDisplayValue();
                }());
                var targetNumber = sourceVtbCardRecordGr.task.number;
                var targetShortDescription = sourceVtbCardRecordGr.task.short_description;

                taskRecordLabelEntryGr.initialize();
                taskRecordLabelEntryGr.label = current.label;
                if (targetShortDescription != ("" || undefined)) {
                    taskRecordLabelEntryGr.title = targetClass + " - " + targetNumber + " - " + targetShortDescription;
                } else {
                    taskRecordLabelEntryGr.title = targetClass + " - " + targetNumber;
                }
                taskRecordLabelEntryGr.table = targetTableName;
                taskRecordLabelEntryGr.table_key = targetSysId;
                taskRecordLabelEntryGr.insert();
            }


        } else if (current.operation() == "delete") {

            //If the current operation is delete and a label entry exists for the task record, delete it
            if (taskRecordLabelEntryGr.next()) {
                taskRecordLabelEntryGr.deleteRecord();
            }
        }



    } else {
        //Synchronize label entry for VTB card with label entry for target record

            //Get VTB record for task if such VTB record exists. Only proceed if it exists.
            var targetVtbCardRecordGr = new GlideRecord("vtb_card");
            targetVtbCardRecordGr.addQuery("task", current.table_key);
            targetVtbCardRecordGr.query();
            while (targetVtbCardRecordGr.next()) {

                //Get label entry for VTB record (if such label entry exists)
                var vtbCardRecordLabelEntryGr = new GlideRecord("label_entry");
                vtbCardRecordLabelEntryGr.addQuery("table_key", targetVtbCardRecordGr.sys_id);
                vtbCardRecordLabelEntryGr.addQuery("label.name", current.label.name);
                vtbCardRecordLabelEntryGr.query();


                if (current.operation() == "insert") {

                    //If the current operation is insert and a label entry does not exist for the VTB card record, create one
                    if (!vtbCardRecordLabelEntryGr.next()) {
                        vtbCardRecordLabelEntryGr.initialize();
                        vtbCardRecordLabelEntryGr.label = current.label;
                        vtbCardRecordLabelEntryGr.title = "Visual Task Board Card - Created " + targetVtbCardRecordGr.sys_created_on;
                        vtbCardRecordLabelEntryGr.table = "vtb_card";
                        vtbCardRecordLabelEntryGr.table_key = targetVtbCardRecordGr.sys_id;
						vtbCardRecordLabelEntryGr.insert();
                    }


                } else if (current.operation() == "delete") {

                    //If the current operation is delete and a label entry exists for the VTB card record, delete it
                    while (vtbCardRecordLabelEntryGr.next()) {
                        vtbCardRecordLabelEntryGr.deleteRecord();
                    }
                }

            }

    }

})(current, previous);

Hi Magnus - sorry to dig up a very old discussion but I have a question about the script above.  

 

I've used it and it does create the records however it seems to get stuck in a loop and creates multiple records both on the VTB and task table side regardless of which side you create your tag.

 

I suspect it is being triggered many times as the script creates a new record which then triggers the script to run again but I'm not very good with scripts so I may be wrong so thought I would ask the expert 🙂 

 

Thank you!