In scoped application development, How to convert String value to date object so that it is compared and manipulated, to add number of days on ui page script ..

mamataj
Kilo Contributor

In scoped application development, How to manipulate date field value to add number of days .

Tried Using below code in Ui action, to add number of days to   start date   which is not working .

  var temp_date=this.getParameter('start_date');

  var s_date= new GlideDateTime();

  s_date.setValue(temp_date);

  var end_date=   new GlideDateTime();

  end_date.setValue(temp_date);

  gs.addInfoMessage('start date',s_date);

  var days=g_form.getValue('number_of_days');

  end_date.addDaysLocalTime(days);

  g_form.setValue('wo_end_date',temp_date);

We want to add number of days to start date to calculate end date .Kindly suggest some solution .

1 ACCEPTED SOLUTION

Hi Mamatha,



GlideDateTime is not available on Client Side, it is only available on the Server Side.


So what you can do is make your End_Date_Field readonly, provide the number of days in Number_of_days, Save.



Make one Before BR and pass the values there-->


var _noofDays = parseInt('current.getValue('number_of_days');


var _start = current.getValue('start_date_field');


var _end = new GlideDateTime(_start);


_end.addDaysLocalTime(_noofDays);


current.setValue('end_date_field',_end);


View solution in original post

5 REPLIES 5

nitish99
Tera Guru

Hi Mamata,



I have one question-: from where are you passing the values to temp_date?



var s_date= new GlideDateTime();                   ==> This will set the current Date to s_date


  s_date.setValue(temp_date);                


  var end_date=   new GlideDateTime();     ==> This will set the current Date to end_date


  end_date.setValue(temp_date);


  gs.addInfoMessage('start date',s_date);


  var days=g_form.getValue('number_of_days');         ==> This will return a string


  end_date.addDaysLocalTime(days);                                         ==> addDaysLocalTime() this function takes integer parameter but you are passing a string


  g_form.setValue('wo_end_date',temp_date);


mamataj
Kilo Contributor

Thanks Nitish for your inputs, We need to fetch the value of date time field "start date " on current form .


Putting the value in temp_date as below:



var temp_date = g_form.getValue('start_date') ;



I tried with parseInt() , it didn't work .


We want to fetch Start date value and calculate end date, adding number of days to start date .Please suggest .


Hi Mamatha,



GlideDateTime is not available on Client Side, it is only available on the Server Side.


So what you can do is make your End_Date_Field readonly, provide the number of days in Number_of_days, Save.



Make one Before BR and pass the values there-->


var _noofDays = parseInt('current.getValue('number_of_days');


var _start = current.getValue('start_date_field');


var _end = new GlideDateTime(_start);


_end.addDaysLocalTime(_noofDays);


current.setValue('end_date_field',_end);


mamataj
Kilo Contributor

Thank you for your time nitish, It worked successfully .