SetValue for a GlideDate object is not working for a Script Include tag

janrameez
Giga Contributor

Hello All,

I trying to set value for a Date Object through the script script. But it is not setting the value that the Client script passing to the Script Include.

Below is my Client Script:

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

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

          return;

    }

var dt = g_form.getValue("u_open");

var ga = new GlideAjax("MyFavoritesAjax");

ga.addParam("sysparm_name", "getFavorites");

  ga.addParam("sysparm_dt", dt);

ga.getXML(ajaxResponse);

function ajaxResponse(serverResponse) {

  var result10 = serverResponse.responseXML.getElementsByTagName("result1");

  var message10 = result10[0].getAttribute("message");

  alert(message10);

}

Script Include is:

var MyFavoritesAjax = Class.create();

MyFavoritesAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  getFavorites : function() {

  var results1 = this.newItem("result1");

  var firstdt = this.getParameter("sysparm_dt");

  gs.addInfoMessage('FirstDate is:'+firstdt);

  var dt = new GlideDate();

  gs.addInfoMessage('DT Object is:'+dt);

  dt.setValue(firstdt);                   // Here, the SetValue is not working for this Date Object.

  gs.addInfoMessage("DT Value before subtracting is:"+dt);

  dt.addDays(-1);

  gs.addInfoMessage(dt);

  results1.setAttribute("message", dt);

},

  type: 'MyFavoritesAjax'

});

The result of this script is as follows(DT Value that should have set with the Date that was sent by client script is not setting, instead, it is showing the current Date):

FirstDate is:29/04/2017

DT Object is:2017-04-03

DT Value before subtracting is:2017-04-03 (This should have been set with the FirstDate value, but it having the current date)

2017-04-02

The same script absolutely fine when I try on a DateTime Object, but this issue is only with the Date Object.

Please let me know, where I need to correct the script for a Date Object.

1 ACCEPTED SOLUTION

rajeshraya
Giga Expert

Hi,



Instead of setValue, please try setDisplayValue(dt) in your code as it is.



Rajesh


View solution in original post

8 REPLIES 8

Hey Janrameez,



I tried this script in BACKGROUND SCRIPT -


setValue(); worked for me if I used GLIDEDATETIME.



var firstdt = new GlideDateTime();


firstdt.setValue('29/04/2017');


var dt = new GlideDate();


  gs.print('DT Object is:'+dt);


  dt.setValue(firstdt);


gs.print('DT:'+dt);


Yes, Nayan. Thats true. But, I only wanted Date value to be set, but not the Date and Time like 29-04-2017 00:00:00.


So, I've chosen the Date object.



Thank you.


rajeshraya
Giga Expert

Hi,



Instead of setValue, please try setDisplayValue(dt) in your code as it is.



Rajesh


var dt = new GlideDate(firstdt) did not work.



But, setDisplayValue(dt) worked like a charm!



Thank you so much for your help!!



BTW, could you please let me know why the setValue won't work?