How to convert duration field to a string value?

malaisamy1
Kilo Contributor

Hi Guys,

My problem is: I want to subtract two date/Time field and the result should stored in another field.

This i have achieved through this code using Business Rule.

"var gdt1 = new GlideDateTime(current.initial_response_date_time.getDisplayValue());  

var gdt2 = new GlideDateTime(current.open_date_time.getDisplayValue());  

var dur = GlideDateTime.subtract(gdt2, gdt1); //the difference between gdt1 and gdt2  

var dur1= new GlideDuration();  

dur1.setValue(dur.getValue());  

current.si_actual_response_duration=dur1.getDurationValue(); "

But the problem is i need to convert this duration field to seconds and this has to be stored in another field.

And also i have one more problem with this script is, the result gives me the duration along with date like this. "1970-01-01 01:00:00"

Can someone help me to resolve this issue?.

My Need is: Two date and time field has to be subtracted and the result should stored in another field as seconds.

Thanks in advance for the help.

Malaisamy J

1 ACCEPTED SOLUTION

sushantmalsure
Mega Sage
Mega Sage

the result you need to store in another field if that is a date/time field then 1970-01-01 01:00:00 is a valid value to store 1 hour.


what's the type of field?


If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

View solution in original post

11 REPLIES 11

no need to change the filed to string; share your code snippet to help you out


If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Hi Sushant,



Thanks for the hint..That works super. now i am able to get values in seconds in duration field .



But the problem is when i apply the business rule for the field it is working reverse.



The condition for my expected result is below



if field si_actual_response_duration is <= 900


if priority is 1- critical



set value(si_response)= met



if field si_actual_response_duration is > 900


if priority is 1- critical



set value(si_response)= Not met


.................................................................



But this is happening reverse.



if field si_actual_response_duration is <= 900


if priority is 1- critical



set value(si_response)=Not met



if field si_actual_response_duration is > 900


if priority is 1- critical



set value(si_response)=Met



May i know why?



Is there any solution for this?




Malaisamy


try using :



if(current.si_actual_response_duration.getNumericValue() <= 900000 && current.priorty==1-critical)



{


set value(si_response)= met;


}


else if(current.si_actual_response_duration.getNumericValue() > 900000 && current.priorty==1-critical)



{


set value(si_response)= not met;


}


If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Hi Sushant,



Really its amazing...super..its working as per my request.




Thank you so much.



Malaisamy


Hi Sushant,



Sorry its not working... That worked for old conditions..



So help me.



This is my code. If any mistake correct me.





  if (current.si_act.getNumericValue()<= '900000' && current.severity_priority== '1 - Critical'){



  current.si_response.setValue('Met');



  }




  else if(current.si_act.getNumericValue()> '900000' && current.severity_priority== '1 - Critical'){



  current.si_response.setValue('Not Met');


  }