
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2017 01:23 PM
I have been asked to automatically put the caller_id in the beginning of the short_description on an Incident Form. I have reviewed with our ServiceDesk and validated their use case asking for this change and it seems legit. Newbie here....I think the right way to go is a Client Script to dynamically update the form onChange. What am I missing?
Here's what I got and how crazy am I:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading){
return;
}
//try to ensure we don't loop and keep processing short description field changes
if (oldValue != ''){
return;
}
//Alter Short Description with "caller_id" colon space short_description
//Get contents of caller_id field and put into var caller
var caller = g_form.getReference('caller_id');
//Get contents of short_description and put into var shortd
var shortd = g_form.getValue('short_description');
//Combine var caller and var shortd into one var called newshortd
var newshortd = (caller +': ' +shortd);
//Set the new value of short_description with the var newshortd
g_form.setValue('short_description', newshortd);
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2017 05:19 PM
Please try below, if this helps.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var shortd = g_form.getValue('short_description');
var caller = g_form.getReference('caller_id', doAlert);
function doAlert(caller) {
if(!shortd.includes(caller.name)){
var newshortd = caller.name +': ' + shortd;
g_form.setValue('short_description', newshortd);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2017 03:27 PM
This doesn't change the Short Description
If I change : if(!shortd) to if(shortd) it runs but I get the onChange script error: RangeError: Maximum call stack size exceeded....
but it does change the short description at fail
It just puts the caller in many many many times with the : shortdescription at the very end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2017 03:29 PM
Can you show me whats your onChange Client Script on short_description?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2017 03:49 PM
I commented everything I had out....and put what you suggested in. Again, this fails to update the Short Description at all "UNLESS" I remove the "!" from the if(!shortd). Then it runs and loops...fails...but eventually puts in caller caller caller .... caller caller : newshortd
So with an empty form, I select a caller from the picker
I then type "This is a short description" in the short_description field
When it runs it loops and I get the error but the short description field does get changed to....
caller name caller name caller name caller name caller name....over and over
at the end it puts in a colon and space -- caller name caller name caller name: This is a short description
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Alter Short Description with "caller_id" colon space short_description
//Get contents of caller_id field and put into var caller
var caller = g_form.getReference('caller_id').name;
//Get contents of short_description and put into var shortd
var shortd = g_form.getValue('short_description');
if(!shortd){
//Combine var caller and var shortd into one var called newshortd
var newshortd = (caller +': ' +shortd);
//Set the new value of short_description with the var newshortd
g_form.setValue('short_description', newshortd);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2017 04:23 PM
Hi Jeff,
I hope the above Client Script runs on change of Caller. Do you have a client script for the change Short Description also?
What is your user case?
You want to populate the Caller name on Short Desc when Short Desc is empty. What do you want to do when Short Description changes?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2017 04:46 PM
The use case
When an ITIL user fills in an incident form to include Caller and Short Description the onChange Client Script will automatically replace the Short Description by putting the Caller into the Existing Short Description as a Prefix:
Example:
I select the caller: Bob Jones
I type in the short description: This is me typing the short description
When I tab out of the short description or click to the next field the short description would become
Bob Jones: This is me typing the short description
The issue I believe is that the onChange is watching short_description and when the onChange script changes the short_description it fires repeatedly until is simply overflows and fails. I need a way for the onChange to run once and find a condition that would cause it to end.