Client Scripts, Script Includes & Scoped Applications

Sue Frost
Giga Guru

I've been working with this discussion which was very helpful:   Client Script Date/Time Functions .

Here is my dilemma.

I created "ClientDateTimeUtils" as a global script include - it has uses far beyond a single scoped application.

I have a scoped application from which I'd like to call the script include. The end result will be to reset the Expiry Date if the Effective Date changes.

The Expiry Date should be 90 days after the Effective Date.

I've been looking at it so long, I don't really see it anymore. I've been poking around the community but I can't get it to work. I'm only see the first

alert in the Client Script that returns "newValue". It appears that the Script Include isn't being called at all and I don't know why.

My client script, running on change of the Effective Date field:

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

  if (isLoading || newValue === '') {

  return;

  }

  //Type appropriate comment here, and begin script below

  var cdt = newValue; //Choose the field to add time from                           <-- was wrong, I have corrected this line as per my reply below

  var addtime = 90; //The amount of time to add

  var addtype = 'day'; //The time type.   Can be day, week, month, year.

  var ajax = new GlideAjax('global.ClientDateTimeUtils');

  //var ajax = new GlideAjax('x_enig_quote_extrm.ClientDateTimeUtils');

  ajax.addParam('sysparm_name', 'addDateAmount');

  ajax.addParam('sysparm_fdt', cdt);

  ajax.addParam('sysparm_addtime', addtime);

  ajax.addParam('sysparm_addtype', addtype);

  ajax.getXML(doSomething);

  alert(newValue);

  function doSomething(response){

  alert('into doSomething');

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

  alert(answer);

  }

}

My global, client callable Script Include:

var ClientDateTimeUtils = Class.create();

ClientDateTimeUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

      ... <snip> ...

//Takes a glide date field and adds time to it.

//params = sysparm_fdt (the first date/time field), sysparm_addtype (type of time to add - day, week, month, year),sysparm_addtime (amount of time to add based on the type).

addDateAmount: function(){

var firstDT = this.getParameter('sysparm_fdt'); //First Date Field

var addTYPE = this.getParameter('sysparm_addtype'); //What to add - day (addDays()), week (addWeeks()), month (addMonths()), year (addYears())

var addTIME = this.getParameter('sysparm_addtime'); //How much time to add

var day = GlideDate();

day.setValue(firstDT);

if(addTYPE == 'day'){day.addDays(addTIME);}

else if (addTYPE == 'week'){day.addWeeks(addTIME);}

else if (addTYPE == 'month'){day.addMonths(addTIME);}

else if (addTYPE == 'year'){day.addYears(addTIME);}

else {day.addDays(addTIME);}

//return "First Date: " + firstDT + " -Time to Add: " + addTIME + " -Add Type: " + addTYPE + " -Added Time: " + day;

return day;

1 ACCEPTED SOLUTION

Thanks for the update Sue. Replace script include with below updated code.


var ClientDateTimeUtils = Class.create();


ClientDateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  addDateAmount: function(){



  var firstDT = this.getParameter('sysparm_fdt'); //First Date Field


  var addTYPE = this.getParameter('sysparm_addtype'); //What to add - day (addDays()), week (addWeeks()), month (addMonths()), year (addYears())


  var addTIME = this.getParameter('sysparm_addtime'); //How much time to add


  var day = GlideDate();


  day.setValue(firstDT);



  if(addTYPE == 'day'){day.addDays(addTIME);}


  else if (addTYPE == 'week'){day.addWeeks(addTIME);}


  else if (addTYPE == 'month'){day.addMonths(addTIME);}


  else if (addTYPE == 'year'){day.addYears(addTIME);}


  else {day.addDays(addTIME);}



  //return "First Date: " + firstDT + " -Time to Add: " + addTIME + " -Add Type: " + addTYPE + " -Added Time: " + day;


  return day;


  },



  _privateFunction: function() { // this function is not client callable



}




});



View solution in original post

15 REPLIES 15

Hi shilpamurthy,



Did you have any success with the above mentioned issue?


I am facing the same issue and not able to figure out the issue.



Thanks


Tushar