gs.datediff() in business rule with 'true' is not picking date difference in seconds.

Ramya72
Kilo Contributor

Hi Team,

var datediff = gs.dateDiff(current.opened_at.getDisplayValue(), gs.nowDateTime(),true);   

Above statement in business rule with 'true' is not picking date difference in seconds.You can find the entire business rule below.If I use the statement with false it is picking the date difference in dd:hh:mm correctly : var datediff = gs.dateDiff(current.opened_at.getDisplayValue(), gs.nowDateTime(),false);   

Please help in fetching the seconds from date diff as I need to fetch the days from seconds.

(function executeRule(current, previous /*null when async*/) {

calculateAge();

function calculateAge()

{

var datediff = gs.dateDiff(current.opened_at.getDisplayValue(), gs.nowDateTime(),true);
    
current.u_incident_age_in_days = datediff;

current.update();

}

})(current, previous);

4 REPLIES 4

Inactive_Us2019
Giga Expert

Hi Ramya,

Try this! You will get output in seconds.

var gdt1 = new GlideDateTime( current.opened_at);

var gdt2 = new GlideDateTime();

var datediff = gs.dateDiff(gdt1,gdt2,true);

Note: The gs.dateDiff() method is not available in scoped applications.

If my reply has helped you,Kindly click the Helpful button.

If my reply is the answer you were looking for, Kindly click the Accepted Solution button.

Hi Lavanya,

Thanks for your response.

After updating the business rule as you said I am not getting incident age in seconds.

Thanks,

Ramya.

 

vkachineni
Kilo Sage
Kilo Sage

What is the data type of the field u_incident_age_in_days

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Ramya72
Kilo Contributor

Data type of  u_incident_age_in_days is duration.