Unable to call script include from client script

tejashree4
Tera Contributor

Requirement--- for sev1 and sev2 incidents, when you select the value in   preliminary caused by business segment (i.e nothing but company value) if the selected value has sev1 true for sev1 incident then problem assigned to filed should get mandatory same way, if the company table has sev1 as false then problem assigned to should not be mandatory.

for sev2 incident if the selected company has sev2 value as true then problem assigned to field should get mandatory. if it is false then no mandatory.

(note: Company table has sev1 and sev2 values for each record )

Client script:

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

        if (isLoading) {

                return;

              }

        var nb=g_form.getValue('number');

        var company1=g_form.getValue('u_preliminary_caused_by');

        var sev=g_form.getValue('severity');

              var gpc = new GlideAjax('Compseverity');

  gpc.addParam('sysparm_name','severitychk');

        gpc.addParam('sysparm_sysid',nb);

        gpc.addParam('sysparm_preliminary',company1);

        gpc.addParam('sysparm_severity',sev);

        gpc.getXML(getresults);

                             

              function getresults(response) {

              var answer = response.responseXML.documentElement.getAttribute("answer");

  alert(answer);

              if(answer=='true')

  {

    g_form.setMandatory('u_problem_owner',true);

  }

  else

  {

  g_form.setMandatory('u_problem_owner',false);

        }

}

}

script include:

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

        if (isLoading) {

                return;

              }

        var nb=g_form.getValue('number');

        var company1=g_form.getValue('u_preliminary_caused_by');

        var sev=g_form.getValue('severity');

              var gpc = new GlideAjax('Compseverity');

  gpc.addParam('sysparm_name','severitychk');

        gpc.addParam('sysparm_sysid',nb);

        gpc.addParam('sysparm_preliminary',company1);

        gpc.addParam('sysparm_severity',sev);

        gpc.getXML(getresults);

                             

              function getresults(response) {

              var answer = response.responseXML.documentElement.getAttribute("answer");

  alert(answer);

              if(answer=='true')

  {

    g_form.setMandatory('u_problem_owner',true);

  }

  else

  {

  g_form.setMandatory('u_problem_owner',false);

        }

}

}

1 ACCEPTED SOLUTION

Rushit Patel2
Tera Guru

Hi Tejashree,



why you are using Script include? if u are just checking value from any reference field(like sev1 field on company table) from incident form. u can use g_form.getReference().



see this page GlideForm (g form) - ServiceNow Wiki


if u cant make it working then tell   me more about table structure then I can write script for u.



****hit helpful/like/correct if it helps


View solution in original post

4 REPLIES 4

Rushit Patel2
Tera Guru

Hi Tejashree,



why you are using Script include? if u are just checking value from any reference field(like sev1 field on company table) from incident form. u can use g_form.getReference().



see this page GlideForm (g form) - ServiceNow Wiki


if u cant make it working then tell   me more about table structure then I can write script for u.



****hit helpful/like/correct if it helps


ashik1
Kilo Guru

Hi Tejashree,


I see your script include code and client script code are same.


Make sure your script include file name is "Compseverity", function name is "severitychk" and you have checked "client callable"


If you still not able to get the expected result pass the script include code, let me try on it


Ashish Kumar Ag
Kilo Guru

Function name is case sensitive and make sure client callable is true.


You can also add log in script include. It might be calling the script include but not returning any value.


tejashree4
Tera Contributor

Thanks all for the help.