Scoped app issue with client Script that calls a script include

ashamankun
Giga Contributor

I have a scoped application and I'm trying to create a check on a due date field on a record producer that only allows a date after 8 weeks using a catalog client script and a script include. Both the client script and the script include are in the scoped application. On the script include the accessibility setting is set to all scopes. It doesn't appear to ever actually run the script include. It just give a pop up saying " ServiceNow says: GlideAjax". 

The exact same code outside of the scoped application works fine.  Scoped apps are new to me and I'm sure I'm just not entirely understanding how they work. Any guidance would be appreciated. 

Thank you!

 

Catalog Client Script:

function onChange(control, oldValue, newValue, isLoading) {
 
if(newValue){
var ga = new GlideAjax('x_ultr2_marketing.CheckDate8Weeks'); //Name of the Script Include
ga.addParam('sysparm_name', 'chkCatDate'); //Name of the function in the script include
ga.addParam('sysparm_date',g_form.getValue('u_due_date')); //Parameter to pass to the script include
ga.getXML(CheckDate8WeeksParse);
	alert(ga);

}
}
//Function that gets the response and will return to the client. You can place your alert in this function
function CheckDate8WeeksParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
	//alert('Got to function');
if(answer == 'true'){
	alert('Got to answer true');
return;
}
if(g_form.getValue('u_due_date') != '' && answer == 'false'){
alert("You must give a lead time of at least 8 weeks. Thank You.");
g_form.setValue('u_due_date', '');
}
 
 

Script Include:

var CheckDate8Weeks = Class.create();
CheckDate8Weeks.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
chkCatDate : function() {
//gs.log("CheckDate8Weeks got to script inlucde"); 
var start = this.getParameter('sysparm_date'); //passing the parameter from the client script
var currDay = gs.now(); //getting the current date


var dif = gs.dateDiff(gs.now(), start, true);
  if (dif < 4838400) {
return false;
}
else
{
return true;
}

}});
1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Plug this in script include code

var CheckDate8Weeks = Class.create();
CheckDate8Weeks.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
chkCatDate : function() { 
var start = this.getParameter('sysparm_date'); //passing the parameter from the client script
var sgd1 = new GlideDate(); 
sgd1.setDisplayValue(start); 
var sgd2 = new GlideDate();
sgd2.setDisplayValue(new GlideDate().getDisplayValue());
 var duration= GlideDate.subtract(sgd1, sgd2); 
var dif= duration.getNumericValue()/86400000;
  if (dif < 7) {
return false;
}
else
{
return true;
}

}});

View solution in original post

5 REPLIES 5

Harsh Vardhan
Giga Patron

just confirming here, 

 

did you try to set the script include "Accessible from" value to "All application scope" ?

 

also put the log in your script include and see are you getting the result or not. 

 

Abhinay Erra
Giga Sage

now() method is not allowed in scoped application. Use new GlideDate().getDisplayValue() instead

Abhinay Erra
Giga Sage

Is start variable storing date/time or just date? You don't have access to dateDiff as well in scoped app

Abhinay Erra
Giga Sage

Plug this in script include code

var CheckDate8Weeks = Class.create();
CheckDate8Weeks.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
chkCatDate : function() { 
var start = this.getParameter('sysparm_date'); //passing the parameter from the client script
var sgd1 = new GlideDate(); 
sgd1.setDisplayValue(start); 
var sgd2 = new GlideDate();
sgd2.setDisplayValue(new GlideDate().getDisplayValue());
 var duration= GlideDate.subtract(sgd1, sgd2); 
var dif= duration.getNumericValue()/86400000;
  if (dif < 7) {
return false;
}
else
{
return true;
}

}});