Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Assigned To Empty and state changes to New

manishakumari
Kilo Contributor

Hi guys

I have written one client script on onChange of Assignment group ,assigned_ to should be empty and state changes to new.

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

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

          return;

    }

g_form.setValue('assigned_to','');

//g_form.clearValue('assigned_to');

g_form.setValue('state', 1);

}

But it is not working I don't know why

Please help me with this

1 ACCEPTED SOLUTION

venkatrajesh
Tera Expert

Hi Monu gupta



try below code to clear the assigned_ to value i.e make it as empty.it should work, i have tried


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


   


  if (isLoading)


          return;


  if (newValue != oldValue)


  {


  g_form.setValue('assigned_to','');


//   g_form.clearValue('assigned_to');


g_form.setValue('state', 1);




  }



PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

17 REPLIES 17

sb1186
Kilo Guru

Hi Monu,



Try the following updated code:



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


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


          return;


    }



if (newValue)


{


g_form.setValue('assigned_to','');


//g_form.clearValue('assigned_to');


g_form.setValue('state', 1);


}


}


not working


What error do you get? Also, can you put an alert inside your if to see if your script enters the loop?


Ia m not getting any error.. I checked with alert also but alert didn't come.