- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2016 03:58 PM
I'm interested in making my templates a little bit smarter with a bit of JavaScript. I'm able to set the Caller to myself using this snippet for the value of Caller in the template:
javascript:gs.user_id()
I then tried to set the Short Description using this snippet:
javascript:g_form.getValue('parent.short_description') + ": add some text here"
That resulted in blanking out the short description when the template was applied. I opened the JavaScript executor in Chrome (ctrl-shift-j) while on the record and running:
alert(g_form.getValue('parent.short_description') + ": add some text here")
That gives me a popup alert box with the text I was hoping would populate in the Short Description field. So the script itself appears to be valid and working as I'd expect. But I just can't get it to run when I put it in for the value of a field in a template.
I'm trying this on a developer instance running Geneva.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2016 08:19 AM
Bradley,
The templates apply the javascript server side, not client side. That's why the first call work, gs is available only server side.
With that being said, you can invoke a script include to do what you want. You would have to first create the script include and it would probably look like;
javascript: new bradleysScriptInclude(current, 'parent.short_description', 'add somemore text');
the script include would probably need to look like;
var bradleysScriptInclude = Class.create();
bradleysScriptInclude.prototype = {
initialize: function( /*GlideRecord*/ task, /*string*/ task_field, /*string*/ text) {
this.task = task;
if (!task || !task.isValidRecord()) {
if (!task.isNewRecord()) {
return;
}
}
return task[task_field] + text;
},
type: "bradleysScriptInclude"
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2016 08:19 AM
Bradley,
The templates apply the javascript server side, not client side. That's why the first call work, gs is available only server side.
With that being said, you can invoke a script include to do what you want. You would have to first create the script include and it would probably look like;
javascript: new bradleysScriptInclude(current, 'parent.short_description', 'add somemore text');
the script include would probably need to look like;
var bradleysScriptInclude = Class.create();
bradleysScriptInclude.prototype = {
initialize: function( /*GlideRecord*/ task, /*string*/ task_field, /*string*/ text) {
this.task = task;
if (!task || !task.isValidRecord()) {
if (!task.isNewRecord()) {
return;
}
}
return task[task_field] + text;
},
type: "bradleysScriptInclude"
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2016 10:07 AM
Brilliant. I hadn't considered the distinction between functions available on the client vs. the server. Thanks for the sample script. I'll work with my admins to give that a whirl.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2016 10:17 AM
You could also just do javascript:current.parent.short_description + 'add some text here'
Not sure why I didnt think of that earlier.
Well I guess I'm not sure if current's available, if its not you may still have to do the scriptinlcude route.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2016 08:15 AM
I couldn't get "current" to work, so I'll probably have to stick with the scriptInclude.