- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 01:18 PM
Is there a way to dynamically pass values through the template fields? For instance, having a short description of "Create mainframe account for <requested_by>" which would pass the matching value through once the template is applied:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 06:18 PM
Thanks John, I haven't tried your code yet, but I did add a GlideRecord query which did the trick:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var gr = new GlideRecord('sys_user');
gr.get(g_form.getValue('requested_by'));
var rb = gr.name;
if (newValue == 'New Mainframe Account') {
g_form.setValue('short_description', newValue + ' for ' + rb);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 06:15 PM
Hey Jeff,
To answer your question about g_form.getValue giving you a sys_id - that's because you're getting a value of a reference field which always has the sys_id as the field value. It would be nice if something like g_form.getDisplayValue() would work, but that would only run server side and not in a client script such as yours.
I would recommend using the g_form.getReference() function with a callback that outputs the referenced user's title which is what you want.
Something like this in your code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var rb = g_form.getReference('requested_by', function(ref) {
return ref.getValue('title'); //title is the field in the user table that shows the full name, but you can choose any field
});
if (newValue == 'New Mainframe Account') {
g_form.setValue('short_description', newValue + ' for ' + rb);
}
}
I did not test that code, but let me know if that helps you out.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 06:18 PM
Thanks John, I haven't tried your code yet, but I did add a GlideRecord query which did the trick:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var gr = new GlideRecord('sys_user');
gr.get(g_form.getValue('requested_by'));
var rb = gr.name;
if (newValue == 'New Mainframe Account') {
g_form.setValue('short_description', newValue + ' for ' + rb);
}
}