The CreatorCon Call for Content is officially open! Get started here.

Automatically update short_description to start with caller_id

jstocton
Kilo Expert

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);

}

1 ACCEPTED SOLUTION

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);


}


}


}  


View solution in original post

30 REPLIES 30

jstocton
Kilo Expert

For what it is worth.  I did not put the correct answer into production.  I debated the requirement several times and the requirement was eventually dropped.  The solution does work...   I just did not feel good about "BENDING" the system to the will of the users when there are OOB views that solve the issue.  Which is what they ended up doing.