Calculate Days open based on sys_created

deepanshanand
Kilo Expert

HI Experts i am trying to write code to calculate no of days a ticket has been opened based on only sys_created_on .
Below is the code that i tweaked little bit but its not working

below is script include:

var CalculateDuration = Class.create();

CalculateDuration.prototype = {

      calculate_duration : function(start) {

              var duration.seconds = {};

duration.days = parseInt(duration.seconds * 100 / 86400,10)/100;

              return duration;

      }

};

Buisness rule where i am calling

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

        var start = current.sys_created_on.getDisplayValue();

      var td = new CalculateDuration();

    var duration = td.calculate_duration(start);

      current.u_days_open = duration.days;

})(current, previous);

Any leads where i am going wrong

1 ACCEPTED SOLUTION

Strange Occurence - below code is changing only 5 records , rest are not updated .


this field is a duration type field


hope that is not going wrong


find_real_file.png


View solution in original post

19 REPLIES 19

Hey Deep,




Directly write a display BR with this


var datedif = gs.dateDiff(current.sys_created_on.getDisplayValue(), gs.nowDateTime());  


gs.addInfoMessage("Days opened"+datedif);




Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


Have a lovely day ahead




Regards,


Divya Mishra


ADDITIONAL HELP: if only days required


display BR


code:



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




// Add your code here


var datedif = gs.dateDiff(current.sys_created_on.getDisplayValue(), gs.nowDateTime());  


var date1= datedif.split(" ");


gs.addInfoMessage("Days opened::"+date1[0]);




})(current, previous);


Hey Deep,




ADDITIONAL HELP: if only days required


display BR


code:



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


// Add your code here


var datedif = gs.dateDiff(current.sys_created_on.getDisplayValue(), gs.nowDateTime());


var date1= datedif.split(" ");


gs.addInfoMessage("Days opened::"+date1[0]);


current.FIELDNAME = date1;


current.update(); // this will make infomessage dissapear



})(current, previous);




post me your feedback




Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


Have a lovely day ahead




Regards,


Divya Mishra


Still same
not able to figure out why days open is still blank.


Daysopen.PNG


Any luck ?