Update field in list view when incident table loads

Will Yerkovich
Tera Contributor

Hello,

I have a requirement to get the 'business elapsed percentage' field from the current SLA of an incident record on the incident list view, so the customer can quickly prioritize incidents. 

find_real_file.png

I was successful in doing this (above screenshot), however, the field only updates in the list view when you click into the record and navigate back to the incident table. How can I get the field to update every time you navigate to the incident table or refresh your browser, so you do not have to click into the record in order to update that field on the list view?

I have also attached the business rule (on Task SLA table) I used to accomplish this for reference (below). If there is any modifications I need to make to the business rule please let me know. It is currently set to run AFTER insert and update.

find_real_file.png

4 REPLIES 4

-O-
Kilo Patron
Kilo Patron

The SLAs for a task (so for an Incident too) are recalculated by a display Business Rule (called Calc SLAs on Display). That is why users need to open the form for it to happen.

So I suppose what you could do is to Create a UI Action for the list that users can press to update the SLAs of the Incidents in the list. However do make sure to build in checks and safeguards against abuse of that refresh functionality, to prevent slowing down or even bringing down the instance. What exactly you need to call for the recalculation to be executed, you can look for it in the Business Rule I mentioned above.

A couple of notes about the BR:

- in it check that get() return true and only if it does, do execute the subsequent statements - actually always do that check.

- I'm not sure if in case just one record is updated it still applies, but normally inc.updateMultiple() needs the value to be set using inc.setValue(). The way it is written and given that only one record is updated anyway, it is better to use just inc.update().

Will Yerkovich
Tera Contributor

Hi Janos,

thanks for your reply. What I am trying to do is have it update automatically, so I am also trying to create a fix script and then create a scheduled job that would call that fix script. I am able to call the fix script from the scheduled job, but having trouble getting the fix script to run. Below is the code for the fix script. The code next to the blue line is the exact code from the "calc SLA's on display' business rule. I am not getting an error when I run it, however, none of the current task sla's for incidents are updating. Anything I am missing here?:

find_real_file.png

Yes, in the 1st wile, it should be gr.sys_id, not current.sys_id. Also the filter for number is wrong: the 1st parameter should be 'task.number', not 'task' and the 2nd parameter should be (a string) 'STARTSWITH' and the 3rd parameter should be (also a string) 'INC'. But the script is not what I would do. It needs to be rewritten from scratch. Right now it starts by loading ALL records in table Task. That means also changes, problems, projects, etc. And then it tries to only handle incidents. That can mean loading millions of records just to handle hundreds or thousands of records. You should start by loading just incidents by writing GlideRecord('incident'), not GlideRecord('task'). Because table incident extends table task, any incident can behave as a task (but not the other way around). Identifying incidents by number is not a good practice anyway. A task's number can deviate from the regular number format in a variety of circumstances and can thus start with something else than INC. Incidents should be identified by Task type - a field all tasks have (so incidents, problems, stories, projects, etc. too). Or by selecting from table incident. I hope it is clear that selecting incidents should be done by specifying incident as table and that the extra query for incident no. is both wrong and not necessary. Lastly, code that is to be reused must go into Script Includes. Fix scripts cannot be called from Scheduled scripts - I don't know how you think you did it. If you need to call some code both from a fix script and a scheduled script, the code should be defined in a Script Include.

I was able to get it working

find_real_file.png