- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2017 10:43 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2017 11:56 AM
Hi,
Instead of setValue, please try setDisplayValue(dt) in your code as it is.
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2017 11:18 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2017 11:27 AM
I think GlideDate class doesn't have addDays() method.
Inorder to use addDays you need to use GlideDateTime() class

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2017 11:47 AM
Hey Janrameez,
setValue(); is not working because of DATE FORMAT.
GLIDEDATE stores date in yyyy-MM-dd format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2017 09:50 PM
Hi Nayan,
Thank you for the response. Changing the setValue to setDisplayValue worked as required.