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

When users can modify a field that is calculated automatically wether it is by a business rule or a client script it invites trouble because users will no question edit the short description (deliberately or by accident) and if they do not follow the established template it will end up in a mess. In my opinion any field that is calculated should be read only.


Yeah, correct!



But, as per the requirement they wants to populate the short description right, they didn't mentioned that user should not do any modification for the same.



If the user doesn't allow to add it manually apart from the populated value, we can add the alert saying that value should not be modified.


Yes you could generate an alert like that but I my view it is a lot of effort for something that has an oob solution. If the users need to remove the caller id field from a view in order to add other fields I would say they have too many fields in the view already.



As I said sometimes we as developers should challenge a customers requirement if there is other simpler solutions.


Yeah! Thanks for your responses



Have a nice day ahead!


jstocton
Kilo Expert

I want to thank everyone for pitching in on this....



I did go ahead and marked the correct answer from Shishir Srivastava.



However, there are multiple answers...his was just the best.   I actually have two solutions in place and will let my customer be the deciding factor on which one to move forward with.     I have Business Rule that works great as many of you suggested.   However, that does not provide the instant gratification the users were looking for...   The client script that Shishir Srivastava suggested works great and provides the instant gratification for the use case.



Again,   Thank you Thank you Thank you for all the assistance.