- 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 10:29 PM
@Research 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 10:07 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader