- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 11:12 AM
Hello All,
I have a requirement to fetch the details from a field.
Table 'Task' records the time (time_worked) a user has worked on the CASE (CS0132374) and RITM (RITM0013737) as below:
The time worked field gets updated every time a user makes update on RITM/CASE (the time gets added automatically). I want to store the both the time a user has worked on RITM and CASE in two different variable so I can use those variables to process ahead as per requirement. I tried creating a BR with table as task. I am getting the value for Case every time using 'current' but not getting the value of RITM here. Unaware of what method to use so that I can get the value of both records in two different variables at the same time.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 02:56 AM - edited 11-06-2023 03:03 AM
Based on what you wrote showed, I would create two business rules, one after on Case and an additional after on Requested Item;
The code would be:
(function executeRule (current, previous) {
var caseUniqueValue = current.getUniqueValue(); // (Only!) In the case BR
var caseUniqueValue = current.request.parent; // (Only!) In the requested item BR
var totalTimeWorked = new GlideDuration(getTotalTimeWorked(caseUniqueValue));
// Use totalTimeWorked to update the entitlement
function getTotalTimeWorked (caseUniqueValue) {
var $ga = new GlideAggregate('task');
$ga.addAggregate('SUM', 'time_worked');
// Only bother with records that have time recorded
$ga.addNotNullQuery('time_worked')
// Include the (parent) case
$ga.addQuery('sys_id', caseUniqueValue)
// Also include any requested items the (parent) case may have
.addOrCondition('ref_sc_req_item.request.parent', caseUniqueValue);
$ga.setGroup(false);
$ga._query();
if ($ga._next())
return $ga.getAggregate('SUM', 'time_worked');
else
return '0';
}
})(current, previous);
Note that you would keep only one of the caseUniqueValue variable declarations only in both Business Rules - the one correct for the given table, of course.
Note also that this is lacking the code that updates the entitlement.
The code makes use of the fact that field time_worked is defined on table Task, the parent both of Case and Requested Item.
Thus the select can be executed against it and it will select both the Case and any Requested Items it may contain.
Also to make it optimal, it does an aggregation in database, returning the total already, not needing any resource intensive in-script processing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 02:51 AM - edited 11-06-2023 02:54 AM
@SANDEEP28 I agree it is not mandatory to use GlideRecord on the same table. Don't mind that as I was switching the tables to RITM, Task, and Case, just to understand how unique value gets printed in logs.
About the time worked field - Yes, I can see this field in the list view of RITM and on the form where end user works but not on the table (as shown by you).
PFA below:
PS: I am getting the right value in time_worked field of RITM. I want to get the current value of that field in a variable and then process it ahead as per my requirement.
I am stuck to get that current record as everytime I am getting the current record value as CASE sys_id as there exists a relationship between case and RITM. Please check the relationship snip in above discussion.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2023 11:08 PM
@swapnil15 First thing you need to check whether "Time worked" is getting populated for RITM record or not. To capture the time worked value, you need to first add the "Time worked" field on the RITM form. Whenever record is viewed, the timer will start as below and once you save the record, time worked value will get save.
To verify, check if Time worked value populating from list view.
Once value is populated, your business rule will work. Refer below doc to know more about "Time worked" field.
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-06-2023 02:09 AM - edited 11-06-2023 02:11 AM
Hello Sandeep,
Thanks for your response.
Yes, I have checked the time worked field is populated for RITM and it captures the time properly as per the user spends time on RITM. Can you tell me how I can fetch the value of time_worked field by using GlideRecord. I am unaware of the filter to add in addQuery condition after gliding the sc_req_item table. I used sys_id is current sys_id but it didn't helped as the updates on RITM are been pushed to CASE hence the script is always fetching the current thread as CASE but not RITM.