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.

OnChange Client script Not working on MRVS

Manu31
Tera Contributor

Hi Team,

 

I have written on onchange catalog client script on  mrvs variable  set which is not working. Could you please help me on this.

 

Note: Written Onchange script on Variable Set (MRVS)

 

Onchange of Variable - StartDate

 

Catalog sclient script

 

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


alert("Hii");
var res = g_form.getValue('startdate');
var ga = new GlideAjax('global.Test');
ga.addParam('sysparm_name', 'valDateScriptChange');
ga.addParam('sysparm_val', res);
ga.getXML(HelloWorldParse);

function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if (answer != "true") {
alert("Start Date cannot be previous");
g_form.clearValue('startdate');
}
}
}

 

 

Script Include

 

var Test = Class.create();
Test.prototype = {
initialize: function() {},

valDateScriptChange: function() {

gs.log("Hiimanu");
var res = this.getParameter('sysparm_val');
var r = gs.dateDiff(gs.now(), res, true) / 86400;
gs.log("Hii" + r);
if (r < 0)
return false;
else
return true;

},


type: 'Test'
};

5 REPLIES 5

Ahmmed Ali
Giga Sage
Giga Sage

Hello @Manu31 

 

Your script include doesn't look to be client callable. update below script in your script include and also select client callable as true.

 

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

valDateScriptChange: function() {

gs.log("Hiimanu");
var res = this.getParameter('sysparm_val');
var r = gs.dateDiff(gs.now(), res, true) / 86400;
gs.log("Hii" + r);
if (r < 0)
return false;
else
return true;

},

type: 'Test'
});

 

If not working, let me know what you are getting in alerts and log messages.

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali