Client Script OnChange - Clear field if another one changes

DesiraeSaysanav
Mega Guru

I would like to create an OnChange Client Script for the Incident form.

When the location changes I need the Configuration Item to be cleared out, this has to work before a save/update is done.

Can someone help me write this as I am not good with scripting. TIA!

1 ACCEPTED SOLUTION

kristenankeny
Tera Guru

In the script field on an onChange client script, you just need to do:



g_form.clearValue('cmdb_ci');


View solution in original post

11 REPLIES 11

How do you have your client script set up? It might help to include a screenshot of the client script so we can see the settings for when to run.


This is what is is currently atfind_real_file.png


James Hammond
Giga Guru

function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue === '') {


          return;


    }




//check to see if the value has truly changed


if(oldValue != newValue){


//clear the value of field below


g_form.clearValue('cmdb_ci');


}


   


}


Thank you, that worked but now once I select a new location and a new CI when I save it clears the CI out again. If i change a second time it keeps it. So I'm having to double save to keep the changes when I select a new location. Any suggestions?


James Hammond
Giga Guru

That sounds odd, the script should only run when you change Location, if you've kept the same settings and just updated the script