Need to set Label of Field based on Task Type

Shane J
Tera Guru

I need to set that label for 'Task' (for Time Cards in this case) to the Task Type of the record within the field.

function onCondition() {

    var task1 = g_form.getReference('task');

        g_form.setLabelOf('task', task1.getTableName());

}

This nets me 'task' for the label, I suppose it is the task table, but not what I want.   So I tried this:

function onCondition() {

    var task1 = g_form.getReference('task');

g_form.setLabelOf('task', task1.sys_class_name);

}

This nets me (for example) 'pm_project' for a Project.   I'd like to build this so I don't have to setup every possible option for types of records we could have in there in a way that doesn't look goofy to the User, thus why I want the table name.

1 ACCEPTED SOLUTION

In that case, I would recommend using both methods and getting creative with when each is called. If starting from a Task's related list, use the onDisplay Business Rule and a client script that sets the label. If starting from Time Card directly, use an onChange client script that calls a script include to return the value of the table's label and set the field label.


View solution in original post

18 REPLIES 18

That did it, thx for the assist Tim!


venkatvraman17
Kilo Guru

You can consider using the Dictionary Override from ServiceNow to update the labels for each task type. By that way you can ignore creating scripts for setting the label for each task type you are going to created.


How can Dictionary Override be used?


He is trying to set the Task field label on the Time Card form. Dictionary Override would not work for this.