onChange script error: ReferenceError: updateResults is not defined function () { [native code] }

cms1
Tera Contributor

Can someone help me understand what line is causing this issue: 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var state = g_form.getValue('state');
if (state == '3') //closed complete {

var parent = g_form.getUniqueValue();
var ga = new GlideAjax('GetParentResults'); //script include
ga.addParam('sysparm_name', 'GetResults'); //function
ga.addParam('sysparm_sys', parent); //pass the value
ga.getXML(updateResults);
} {

function updateResults(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// alert(answer);
if (answer === '') {
g_form.setValue('overall_status', '');

} else {

var textToFind = 'Fail';
if (answer.indexOf(textToFind) == -1) { // true if text does not contain textToFind
g_form.setValue('overall_status', 'Pass');
} else
g_form.setValue('overall_status', 'Fail');
}
}
}

1 ACCEPTED SOLUTION

Prince Arora
Tera Sage
Tera Sage

@cms1 ,

There exist an unwanted bracket as shown in screenshot, Please check the all the opening and closing brackets in the code and try again!

PRINCE_ARORA_0-1675245525718.png


Please mark my answer helpful, if it works for you.

View solution in original post

2 REPLIES 2

Sai Shravan
Mega Sage

Hi @cms1 ,

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  if (isLoading || newValue === '') {
    return;
  }

  var state = g_form.getValue('state');
  if (state == '3') { // closed complete
    var parent = g_form.getUniqueValue();
    var ga = new GlideAjax('GetParentResults'); //script include
    ga.addParam('sysparm_name', 'GetResults'); //function
    ga.addParam('sysparm_sys', parent); //pass the value
    ga.getXML(updateResults);
  }
}

function updateResults(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  // alert(answer);
  if (answer === '') {
    g_form.setValue('overall_status', '');
  } else {
    var textToFind = 'Fail';
    if (answer.indexOf(textToFind) == -1) { // true if text does not contain textToFind
      g_form.setValue('overall_status', 'Pass');
    } else {
      g_form.setValue('overall_status', 'Fail');
    }
  }
}

 

 

In the Line 
if (state == '3') //closed complete { should be -- > if (state == '3') { // closed complete 
and check the state value you are comparing it is a string, try to compare without quotes.

Regards,
Shravan.

Please mark as the correct answer if this helped you

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Prince Arora
Tera Sage
Tera Sage

@cms1 ,

There exist an unwanted bracket as shown in screenshot, Please check the all the opening and closing brackets in the code and try again!

PRINCE_ARORA_0-1675245525718.png


Please mark my answer helpful, if it works for you.