- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2017 11:45 AM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 06:27 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 06:27 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 07:32 AM
OK, so I have some of this working:
I have a Display BR with the following script setup:
g_scratchpad.tn = current.task.sys_class_name;
and a UI Policy with this:
function onCondition() {
g_form.setLabelOf('task', g_scratchpad.tn);
}
That at least sets the field label correctly at time of load. I can't get the OnChange to work though - I keep getting 'null'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 07:48 AM
You need to call the specific function by adding this between lines 5 and 6 of your client script:
ga.addParam('sysparm_name','getTaskFilter');
ga.addParam('task_id', newValue);
Then, in your script include, add this between lines 4 and 5:
var taskID = this.getParameter('task_id');
You will have the task's sys_id at that point. Query the task table for that sys_id, get the table name, query the sys_db_object table for that table name, and get the label.
There may be an easier, more straight-forward way, but that's the best I can come up with at the moment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 08:01 AM
Can't I skip the Task table query and just feed back the task.sys_class_name?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 08:05 AM
That would give you "change_request" or "incident" or "pm_project_task." If you want the label, you would need to do another query to get it.