How to set True a billable field after 10days of ticket closure

Research
Tera Guru

Hi All

 

Can any one please guide me please with script 

How to set the Billable field as true once the ticket (Part requirment ) is closed 
please guide me
Field Service Management part requirement 

Research_1-1699180230689.png

I want to set true after 10days of Ticket closure 
Once it crossed 10days of ticket closed
I want to set Billable field as True 


Please guide me.

Thanks.





 

 

2 ACCEPTED SOLUTIONS

SANDEEP28
Mega Sage

@Research You can use below script. I have tried it for incident table. You can simply change it according to your table name, closure date field and closure state value

 

var grIncident = new GlideRecord('incident');  // replace your table name here
grIncident.addQuery('state', '7')   // check your closure state value and replace it here
grIncident.query();
while (grIncident.next())
{
var closedDate = grIncident.closed_at.getDisplayValue();    // replace your closure date field name here 
var todayDate = new GlideDateTime();

dur = gs.dateDiff(closedDate , todayDate);
var dateDifference = new GlideDuration(dur);
var diffDays   = dateDifference.getDayPart();
if (diffDays == 10 )  // number of days 10
{
grIncident.billable = true;   // replace your billable field name here
grIncident.update();
}
}


  If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

View solution in original post

Hello @Research ,

 

Please use below code-

var getDate = GlideDate();
getDate.addDays(-10);
var gr = new GlideRecord('incident');
gr.addEncodedQuery('closed_atON'+getDate+'^state=7');
gr.query();
while(gr.next()){
    gr.billable= true;
    gr.update();
}

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

 

View solution in original post

6 REPLIES 6

@Research  If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

Ankur Bawiskar
Tera Patron
Tera Patron

@Research 

are you tracking somewhere when the Ticket was closed i.e. some Ticket closure field of type date/time?

If yes then you can easily handle this using flow designer without any scripting and check if the 10 days are crossed

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader