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

Tim Deniston
Mega Sage
Mega Sage

I would start with an onDisplay business rule. Using g_form.getReference() is causing your form to do a server-side query as soon as the conditions are met and it's bringing back the entire record (an incident, for example).



In the onDisplay BR, you could get the table of the task, query the Tables (sys_db_object) table, and get the Label from there.



All this assumes that you know what the Task is before you start creating the Time Card. If not, I would recommend writing a client-callable script include, call it using GlideAjax from your client script, and then only returning the label you need, not the entire record like the getReference does.


You lost me with the last paragraph.


Are you ever creating a Time Card directly and not via a Task/Incident/Change/etc.? If, for example, you have a Time Card related list at the bottom of the Incident form and click New from there, you could use the onDisplay business rule. If you are using a Time Card module in the Application Navigator (left-hand column), then you would need to use the Script Include and call it using GlideAjax from a client script.


We'll be doing both.