- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2024 06:54 AM
Hello Folks!
I want to call a script include from a field style to 'highlight specific fields (due date field where the date is less that 48 hours from now).
I created a script include which seems to be working fine (tested in console) - doing its job.
But when I want to call it from a field style value, it highlights all of the fields on the list view.
Field style:
Script Include:
Where is the catch? What am I missing?
BR
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2024 06:37 AM
Let me know if you want anything further explained 🙂
var dueDateSchedule = Class.create();
dueDateSchedule.prototype = {
initialize: function() {},
dueDateCalendar: function(current) {
var encodedQuery = 'due_dateISNOTEMPTY^due_dateRELATIVEGT@minute@ahead@0^due_dateRELATIVELT@dayofweek@ahead@4';
//Validate that the current record passes the above encodedQuery condition
var passedEncodedQuery = GlideFilter.checkRecord(current, encodedQuery);
//If it doesn't (e.g due date is empty)
//we return false to not apply the field style
if (!passedEncodedQuery)
return false;
//Assumption is the following segment of your code worked
var now = new GlideDateTime();
var dur = new DurationCalculator();
dur.setSchedule('2a13e7ad87e6ce10764276a7cebb353a');
dur.calcScheduleDuration(now, current.getValue('due_date'));
var businessTimeDiff = Math.round(dur.getSeconds() / 3600); //Business time in hours
var totalTimeDiff = Math.round(dur.getTotalSeconds() / 3600); //Total time in hours
if (businessTimeDiff <= 48 && businessTimeDiff >= 0)
return true;
return false;
},
type: 'dueDateSchedule'
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2024 07:02 AM
Hi,
Your script include isn't using the 'current' record, it just querying all incident records and looping over them
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2024 07:56 AM
Hi Kieran,
So I'm supposed somehow to push required records(incidents) to some kind of an array and then return it?
Or is there some other way.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2024 08:02 AM
Can you share your code (not a screenshot) and I'll happily amend and provide guidance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2024 10:45 AM
Sure, much appreciated, here you are.
var dueDateSchedule = Class.create();
dueDateSchedule.prototype = {
initialize: function() {},
dueDateCalendar: function(current) {
var GRInc = new GlideRecord('incident');
GRInc.addEncodedQuery('due_dateISNOTEMPTY^due_dateRELATIVEGT@minute@ahead@0^due_dateRELATIVELT@dayofweek@ahead@4');
GRInc.query();
while (GRInc.next()) {
var gdt = new GlideDateTime();
//gdt.setDisplayValue('2024-06-05 12:00:00');
var dueDate = new GlideDateTime(GRInc.due_date);
var dur = new DurationCalculator();
dur.setSchedule('2a13e7ad87e6ce10764276a7cebb353a');
dur.calcScheduleDuration(gdt, dueDate);
var businessTimeDiff = Math.round(dur.getSeconds() / 3600); //Business time in hours
var totalTimeDiff = Math.round(dur.getTotalSeconds() / 3600); //Total time in hours
if (businessTimeDiff <= 48 && businessTimeDiff >= 0) {
// gs.print("Incident: " + GRInc.number + ' ' + 'all time: ' + totalTimeDiff + ' business time: ' + businessTimeDiff);
return true;
} else {
return false;
}
}
},
type: 'dueDateSchedule'
};