- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2016 12:49 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 10:01 AM
Please check your instance. I have created a new onchnage client script and script include. It is working as expected.
onChange:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('ValidateDate');
ga.addParam('sysparm_name','dateValidation');
ga.addParam('sysparm_date',newValue);
ga.getXML(CallBack);
function CallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer=='true'){
alert("pls select atleast 48hrs or more from now");
g_form.setValue('lpar_refreshed','');
}
}
}
Script include:
var ValidateDate = Class.create();
ValidateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
dateValidation: function(){
return (gs.dateDiff(gs.nowDateTime(),new GlideDateTime(this.getParameter('sysparm_date')), true)/3600<48);
},
type: 'ValidateDate'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 03:03 AM
Hi Sirangi,
you can try the below
var days = gs.dateDiff(current.field_name, gs.nowDateTime(),false);
the above will give the difference in days, and you can put a condition like days >= 2
if you should do this from client-side script then create a script include and with glideajax call, you can apply the above logic.
Thanks and regards,
Swamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 07:22 AM
Hi , thanks for response.
i will explain my requirement exactly .
when user selects some date in the calendar (as shown the varibale in the image above) , that date or duration selected by him should be 48hrs from the time he is placing request , if < 48hrs then a dialogue box shuld pop out saying that "Duration selected should be atleaset 48hrs minimum"/
please give the script for this .
thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 07:38 AM
Hi Vijay,
I have just taken a part of the script from the below thread
Client Script Date/Time Functions
client script:
- var cdt = g_form.getValue('due_date'); //change the field name as per form
- var dttype = 'minute'; //this can be day, hour, minute, second. By default it will return seconds.
- var ajax = new GlideAjax('ClientDateTimeUtils');
- ajax.addParam('sysparm_name','getNowDateTimeDiff');
- ajax.addParam('sysparm_fdt', cdt);
- ajax.addParam('sysparm_difftype', dttype);
- ajax.getXML(doSomething);
- function doSomething(response){
- var answer = response.responseXML.documentElement.getAttribute("answer");
- if(answer < 2880)
- {
- alert("Duration selected should be atleaset 48hrs minimum");
- g_form.setValue('field_name','');
- }
- }
Script include
name:ClientDateTimeUtils
client callable: true
- var ClientDateTimeUtils = Class.create();
- ClientDateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
- //Takes a Single Date/Time Field and returns its time difference from nowDateTime().
- //params = sysparm_fdt (the first date/time field), sysparm_difftype (time based format to return result. See "_calcDateDiff" function comments)
- getNowDateTimeDiff: function(){
- var firstDT = this.getParameter('sysparm_fdt'); //First Date-Time Field
- var diffTYPE = this.getParameter('sysparm_difftype'); // Date-Time Type to return the answer as. Can be second, minute, hour, day
- var diff = gs.dateDiff(gs.nowDateTime(), firstDT, true);
- var timediff = this._calcDateDiff(diffTYPE, diff);
- //return "getNowDateTimeDiff: FIRST DT: " + firstDT + " -DIFFTYPE: " + diffTYPE + " -TIME DIFF: " + timediff;
- return timediff;
- },
- _calcDateDiff: function(diffTYPE, seconds){
- var thisdiff;
- if (diffTYPE == "day"){thisdiff = seconds/86400;}
- else if (diffTYPE == "hour"){thisdiff = seconds/3600;}
- else if (diffTYPE == "minute"){thisdiff = seconds/60;}
- else if (diffTYPE == "second"){thisdiff = seconds;}
- else {thisdiff = seconds;}
- return thisdiff;
- }
- });
Thanks and regards,
Swamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 08:46 AM
Hi , can u share your contact . i need to discuss on this issue. i tried
different ways but its not working . so if you are ok to discuss then i
will contact you .
THanks .
On Tue, Sep 13, 2016 at 10:39 AM, amaradiswamy <