- 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 08:07 AM
I think we're crossing wires. I should be able to pass the task.sys_class_name as a parameter to the Script Includes via the Client Script, then use that parameter to query the sys_db_object table in the Script Includes to get the Label from there and return it as an 'answer' - right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2017 08:12 AM
I realize now that the entire reason you have me doing two queries is to avoid getReference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2017 08:17 AM
I don't know of any way to get the table name of the reference field directly on the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2017 09:22 AM
CS:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('TaskLabelUpdate');
ga.addParam('sysparm_name','getTaskLabel');
ga.addParam('task_id', newValue);
ga.getXML(doAlert);
}
// Callback function to process the response returned from the server
function doAlert(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setLabelOf('task', answer);
}
Script Includes, set to 'Client Callable':
var TaskLabelUpdate = Class.create();
TaskLabelUpdate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getTaskLabel: function() {
var taskID = this.getParameter('task_id');
var tn = new GlideRecord ('task');
tn.addQuery('sys_id', taskID);
tn.query();
while (tn.next()){
var thename = tn.sys_class_name;
alert(thename);
var tab = new GlideRecord('sys_db_object');
tab.addQuery('name', thename);
tab.query();
while (tab.next()){
var retVal = tab.label;
return retVal;
}
}
},
type: 'TaskLabelUpdate'});
****
Still getting 'null' and losing my mind. I know my query is sound because I setup a BR to verify that's working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2017 09:27 AM
Try removing this line from your script include: alert(thename);
It might be erroring out since that's a client-side function and you're trying to run it server-side.