- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2022 08:16 PM - edited 01-07-2023 07:07 PM
Hi Everyone,
I am using a Client Script and Script Include to check that the Outage Begin date should be with in the related change Window. This should work for all users in different time zones. The Client Script and Script Include works fine if the user's profile date format is yyyy-MM-dd , and doesn't work for any other date formats. Please let me know how to make the Client Script and Script Include work for all date formats.(Note: if the user's profile date format is not "yyyy-MM-dd" , the alert is triggering even when Outage Begin date is with in the related change Window)
Kindly help me with the issue.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 06:10 AM
I modified it to take the client side timezone into account. How does it work?
var Checkbegindate = Class.create();
Checkbegindate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkStartofChange: function(){
var begin = new GlideDateTime();
begin.setDisplayValue(this.getParameter('outageStartDate'));
begin = begin.getNumericValue() - begin.getTZOffset();
var changeId = this.getParameter('changeId'); //the changeID
var changeGR = new GlideRecord('change_request');
changeGR.get(changeId);
var ChangeStart = new GlideDateTime();
ChangeStart.setDisplayValueInternal(changeGR.start_date);
ChangeStart = ChangeStart.getNumericValue();
var ChangeEnd = new GlideDateTime();
ChangeEnd.setDisplayValueInternal(changeGR.end_date);
ChangeEnd = ChangeEnd.getNumericValue();
if(begin < ChangeStart || begin > ChangeEnd){
return false;
}
else{
return true;
}
},
type: 'Checkbegindate'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2022 09:07 AM
Hi.
Can you try this script include?
var Checkbegindate = Class.create();
Checkbegindate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkStartofChange: function(){
var begin = new GlideDateTime();
begin.setDisplayValue(this.getParameter('outageStartDate'));
var changeId = this.getParameter('changeId'); //the changeID
var changeGR = new GlideRecord('change_request');
changeGR.get(changeId);
var ChangeStart = new GlideDateTime();
ChangeStart.setDisplayValueInternal(changeGR.start_date);
var ChangeEnd = new GlideDateTime();
ChangeEnd.setDisplayValueInternal(changeGR.end_date);
if(begin < ChangeStart || begin > ChangeEnd){
return false;
}
else{
return true;
}
},
type: 'Checkbegindate'
});
setDisplayValue(String asDisplayed)
setDisplayValueInternal(String value)
The references are here.
https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/c_APIRef
Best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 03:17 AM
Hi @Community Alums ,
Thank you so much for your response.
It works fine if the user's timezone is GMT. and doesn't work for other time zones as it is considering the Offset between the timezone and GMT . Could you please suggest , what we can do to get this work for all timezones
Thank you 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 06:10 AM
I modified it to take the client side timezone into account. How does it work?
var Checkbegindate = Class.create();
Checkbegindate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkStartofChange: function(){
var begin = new GlideDateTime();
begin.setDisplayValue(this.getParameter('outageStartDate'));
begin = begin.getNumericValue() - begin.getTZOffset();
var changeId = this.getParameter('changeId'); //the changeID
var changeGR = new GlideRecord('change_request');
changeGR.get(changeId);
var ChangeStart = new GlideDateTime();
ChangeStart.setDisplayValueInternal(changeGR.start_date);
ChangeStart = ChangeStart.getNumericValue();
var ChangeEnd = new GlideDateTime();
ChangeEnd.setDisplayValueInternal(changeGR.end_date);
ChangeEnd = ChangeEnd.getNumericValue();
if(begin < ChangeStart || begin > ChangeEnd){
return false;
}
else{
return true;
}
},
type: 'Checkbegindate'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 02:22 AM
Hi @Community Alums ,
Thank you so much!!
It is working as expected.