Script include returns 'undefined' value

mdsannavulla
Kilo Guru

Hi All,

I have written a client callable script include to set some reference field values on SRM form.

But whenever script include returns 'undefined' value the reference field values are setting with some value and the color of the field is changed to green even though the filed is empty. Please see the below screen shot

Untitled.png

Please let me know if you have any idea on this

1 ACCEPTED SOLUTION

I fixed this issue by modifying the client side script.



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


    if (isLoading) {


          return;


    }


if (newValue != '')


{


locationValues(newValue);


}


else{


if(g_form.getValue('location1') != "")


  g_form.setValue('location1',"");


if(g_form.getValue('location2') != "")


  g_form.setValue('location2',"");


if(g_form.getValue('location3') != "")


  g_form.setValue('location3',"");


if(g_form.getValue('location4') != "")


  g_form.setValue('location4',"");


  }


}


function locationValues(newValue){


    var ajax = new GlideAjax('SiteContactChange2');


  ajax.addParam('sysparm_name','getSiiteContact2');


  ajax.addParam('sysparm_id2',newValue);


  ajax.getXML(getResult);


}



function getResult(serverResponse){


var result = serverResponse.responseXML.getElementsByTagName("result");


var locat1 = result[0].getAttribute("loc1");


g_form.setValue('location1',locat1);


var locat2 = result[0].getAttribute("loc2");


if(locat2 != "undefined"){


  g_form.setValue('location2',locat2);


  }


  else


  {


  if(g_form.getValue('location2') != "")


  g_form.setValue('location2',"");


  if(g_form.getValue('location3') != "")


  g_form.setValue('location3',"");


  if(g_form.getValue('location4') != "")


  g_form.setValue('location4',"");


        return;


  }



var locat3 = result[0].getAttribute("loc3");



  if(locat3!= "undefined"){



  g_form.setValue('location3',locat3);


  }


  else


  {


  if(g_form.getValue('location3') != "")


  g_form.setValue('location3',"");


  if(g_form.getValue('location4') != "")


  g_form.setValue('location4',"");


        return;


  }


var locat4 = result[0].getAttribute("loc4");



if(locat4!= "undefined"){



  g_form.setValue('location4',locat4);


  }


  else


  {


  if(g_form.getValue('location4') != "")


  g_form.setValue('location4',"");


  return;


  }



}


View solution in original post

9 REPLIES 9

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Md,



It sets the blank value returned from the script include. You can get the value on the client editor to check the same.


'By using if condition on client side I checked whether the value is 'undefined' or not, but issue here is whenever the 'name' field on SRM form changes the script include will run and it should set the values.


It is working as expected on first time but when I changed the name field then it is not working as expected if the script inclide returns 'undefined' value


What is the expected behavior when the script returns undefined?


When it returns undefined value then field color is changing to green color even though the field is empty