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

rajeshraya
Giga Expert

Hi,



Please try replacing "var dt = new GlideDate();" with var dt = new GlideDate(firstdt); and remove the line "dt.setValue(firstdt); " from your code.



Let me know if it worked or not. If not, what values you are receiving after modifying the code.



Rajesh


dvp
Mega Sage
Mega Sage

I think GlideDate class doesn't have addDays() method.



Inorder to use addDays you need to use GlideDateTime() class


nayanawadhiya1
Kilo Sage

Hey Janrameez,



setValue(); is not working because of DATE FORMAT.



GLIDEDATE stores date in yyyy-MM-dd format.


Hi Nayan,



Thank you for the response. Changing the setValue to setDisplayValue worked as required.