- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2016 10:44 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2016 10:51 PM
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?
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 03:20 AM
no need to change the filed to string; share your code snippet to help you out
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 03:28 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 03:41 AM
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;
}
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 07:14 AM
Hi Sushant,
Really its amazing...super..its working as per my request.
Thank you so much.
Malaisamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 07:29 AM
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');
}