- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 02:33 AM
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
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 06:25 AM
@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 !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 08:56 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 02:55 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 05:46 AM
Hi @Harsh_Deep Appreciate for your solution
Can you please help me with script please
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 08:56 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 06:25 AM
@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 !!