Calling script include in on submit client script (not setting value)

Venky Kshatriy2
Tera Contributor

Hi team,

 

I am calling script include and setting value of variable but the value is not setting,

 

script include:

var DecisionTable = Class.create();
DecisionTable.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getRiskrating: function() {


        var getfrom = this.getParameter('sysparm_from');
        var getto = this.getParameter('sysparam_to');
        // var vk ="u_to2="+getto +"^u_from1="+getfrom+"^EQ";
        var vk = "u_from1=" + getfrom;
        var vk1 = "u_to2=" + getto;


        var queastion_table = new GlideRecord("sys_decision_question");
        queastion_table.addQuery('decision_table', "4c171a6147878610f5539de4116d43f7");
        // queastion_table.addQuery('condition', vk);
        queastion_table.addEncodedQuery('conditionLIKE' + vk1);
        queastion_table.addEncodedQuery('conditionLIKE' + vk);
       
        queastion_table.query();
        if (queastion_table.next()) {

            var condition_value = queastion_table.getDisplayValue('answer');
            var risk_rating = condition_value.slice(45);
        //  gs.log('Risk rating is'+risk_rating);
            return risk_rating;
        }

    },

    type: 'DecisionTable'
});
 
 
On submit client script:
 
  var vk = new GlideAjax("DecisionTable");
    vk.addParam('sysparm_name', 'getRiskrating');
    vk.addParam('sysparm_from', g_form.getValue('from'));
    vk.addParam('sysparam_to', g_form.getValue('to'));

    vk.getXML(risk);

    function risk(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        //alert(answer);
        g_form.setValue('risk_rating',answer);
    }
 
VenkyKshatriy2_0-1721306974793.png

but its working fine in on change client script

 

Why  am going on submit in our form there is no on change of variable , Why I need on submit if risk rating is high abort the action and display the two variable & mandatory the variable if it risk rating is low na allow to user to submit the form

 

If any one knows abt this kind of scenario could please help me this 

 

1 REPLY 1

Nicholas_Gann
Mega Guru

From the above image it looks like you're using the back-end Catalog Item/Record Producer form, not the portal one, so I believe usage of waits with an onSubmit Client Script will be possible (on portal it won't be). 

 

Looking at your Client Script I don't see the usage of a wait. See GlideAjax - Client (servicenow.com) but you should be using getXMLWait() instead of getXML() if you want this to work with an onSubmit as the submit will progress without waiting for the outcome of the GlideAjax call without it.