- 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 01:50 PM
Hi Jeff,
Currently templates do not have this capability. They store the values as encoded query strings (e.g. active=true^requested_by=(sys_id)). What you're looking for is the ability to put a display value in that string which is not currently available.
You might be able to do this with a before business rule that would find your meta strings and do the appropriate replacements. We did something similar in live coding happy hour.
Live Coding Happy Hour Recap for October 21, 2016 - Dot-walking your objects (Part 1)
Live Coding Happy Hour Recap for October 28, 2016 - Dot-walking your objects (Part 2)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2020 02:44 AM
Hi Chuck,
I'm trying to fetch the template variable in a Business Rule, so that I can prompt the submission of a new template creation with unwanted variables values in it.
I guess the link you have provided would help me for that. unfortunately I'm unable to access these link.
current.variable, current.template does not work.
Thank You!
Best Regards,
Manisha

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 01:59 PM
I searched and couldn't see a quick way to insert javascript / notation like ${requested_by}, so that quickest option is probably to add a business rule (or client script since this is a template), that runs when short description changes to New mainframe account for, and take the action of setting short_description=short_description + " " + requested_by
You would have to confirm that applying a template triggers the onChange action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 05:50 PM
Thanks Chuck and Darius for your responses, they were very helpful. I set up a client script onChange of short description and it is working, except it is putting in the sys_id of the requested_by rather than the name. Do you know what I am missing?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var rb = g_form.getValue('requested_by');
if (newValue == 'New Mainframe Account') {
g_form.setValue('short_description', newValue + ' for ' + rb);
}
}