Defined related list of assets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2015 08:44 AM
I am attempting to create a defined related list of assets to apply to sc_task. In our departure process, a RITM is generated to track the progress of the departure and an SCTASK is created to collect the assets assigned to the leaving employee. The requestor of the RITM is the manager of the leaving employee. The defined related list should appear on the SCTASK and include only the assets that are assigned to the leaving employee. When the RITM is generated, the RITM sys_id is applied to a "Departure RITM" reference field on the user record.
To start, I must first query the user table to find a user record where the Departure RITM equals the parent.request_item of the hardware return SCTASK. Then, query the alm_asset table for assets assigned to the found user record.
The 'Query with' code on the relationship is:
var userRec = new GlideRecord('sys_user');
userRec.addQuery('u_departure_ritm',parent.request_item.sys_id);
userRec.query();
if(userRec.next()){
current.addQuery('assigned_to',userRec.sys_id);
current.addNotNullQuery('assigned_to');
}
When I open the hardware return task, where I know the RITM is applied to a user record, I get the expected one asset record in the related list. SUCCESS
However, when I open any other SCTASK, where I know the RITM is NOT applied to a user record, the related list contains all assigned assets. FAIL
I have used logging to show that the code is working correctly in the first scenario and that the userRec.next() does not run in the second scenario. I am looking for how to return a blank related list when no assigned assets record should be found.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2015 01:25 PM
Try adding a if statement that adds a filter if the returned rows are 0 BEFORE the while loop.
var userRec = new GlideRecord('sys_user');
userRec.addQuery('u_departure_ritm',parent.request_item.sys_id);
userRec.query();
if (userRec.getRowCount() == 0){
current.addQuery('whatever goes here to make nothing appear');
}else{
if(userRec.next()){
current.addQuery('assigned_to',userRec.sys_id);
current.addNotNullQuery('assigned_to');
}