How to get the difference between 2 date fields in scoped application

vasu17
Tera Contributor

Hi,
Please help on this ,
i want to get difference between 2 date fields (start and end dates) and populate in duration field for the scoped application by using client script 
i have used the script it's worked for global but for the scoped it is not working

here are the scripts both are in same scoped application
Script include:

var DateFormatUtils = Class.create();
DateFormatUtils.prototype = {
    initialize: function() {
    },
calculate: function() {
  return gs.dateDiff(this.getParameter('sysparm_strt'),this.getParameter('sysparm_end'), false);        
    },
    type: 'DateFormatUtils'
};
client script:
function onChange(control, oldValue, newValue, isLoading) {

  var strt = g_form.getValue('start_date');//set this as start date
  var end = g_form.getValue('end_date');//set this as end date
  var ajax = new GlideAjax('DateFormatUtils');
  ajax.addParam('sysparm_name','calculate');
  ajax.addParam('sysparm_strt',strt);
  ajax.addParam('sysparm_end',end);
 ajax.getXMLAnswer(function(answer){
        if(answer != ''){

  //ajax.getXMLWait();
  //var answer = ajax.getAnswer();
  g_form.setValue('duration', answer);
        }
 });
}
please modify this script if anything wrong for the scoped application
Thanks in advance
8 REPLIES 8

Sayali Gurav
Tera Guru
Tera Guru

Hello @vasu17 ,

You can try it by using client script, you can use following javascript code in your client script :

 

SayaliGurav_2-1697027952690.png

 

 

SayaliGurav_1-1697027783910.png

 

 

Mark helpful & correct if applicable.

Thanks & Regards,

Sayali Gurav

 

HI @Sayali Gurav ,

When i use above code but it's not working it is showing some invalid data, please help on this

vasu17_1-1697036582968.png

Thanks

Hello @vasu17 ,

This script will helps you to solve your issue :

SayaliGurav_0-1697099837754.png

Compare this script with your script.

 

If this applicable for your case please mark correct & helpful.

Thanks & Regards,

Sayali Gurav

Hi @Sayali Gurav 

Tried the same script but no luck😥
not sure which methods are work for the scoped applications

vasu17_0-1697106324031.png

Thanks,