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

Harsh_Deep
Giga Sage
Giga Sage

Hello @Research 

 

You can write schedule job that will run everyday.

And there you have to glide same table and then you have to get closure code.

Then write date.addDays(10)

Then check for if condition if true then update your field billable as true.

 

Please accept my solution and mark as helpful if it helps you.

Research
Tera Guru

Hi @Harsh_Deep  Appreciate for your solution 
Can you please help me with script please 

 

Thanks in advance

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.

 

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 !!