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
‎09-18-2015 04:12 PM
I see where you're going with this and I don't have any specific advice for that approach. However, if you're not completely married to this idea you may be open to another one. It sounds to me like a list collector might work here also. Same qualifier could be used so that only the affected person's assets are listed and it's a little cleaner for the manager who is completing the form to use. Just my two cents if that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2015 10:17 AM
Mike,
Thanks for the reply. We were actually able to work work this out with a defined related list. We created a new record under System Definition > Relationships
The Applies to table is Catalog Task (sc_task) and the Queries from table is Asset (alm_asset). The Query with script is as follows:
var userFound = '';
//if catalog item is Departure and Business Service is Departure - Hardware
if(parent.request_item.cat_item == 'b0e389b541153500075eae4ff4403379' && parent.u_business_service == 'b62d12616f628200b8ec7f75f110c783'){
//find the user record that has the RITM in the u_departure_ritm field; get the sys_id
var userRec = new GlideRecord('sys_user');
userRec.addQuery('u_departure_ritm',parent.request_item.sys_id);
userRec.query();
if(userRec.next()){
userFound = userRec.sys_id +'';
}
}
//query the Asset table for all assets assigned to the user sys_id
current.addQuery('assigned_to',userFound);
current.addNotNullQuery('assigned_to');
Then, on the related list we checked the Omit if empty box, so the list will only appear on the Departure Hardware SCTASK and ONLY if there are assigned assets.
This was a huge win for us so I hope that this helps someone.
Regards,
Chad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 12:05 PM
Chad -- this is great, it definitely narrowed down my list. However, it seems to be finding the first user in my user table rather than the user in Requested_for. Any ideas?
Thanks,
Kim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 08:37 AM
Kim,
Without seeing how you set it up, the first thing that comes to mind is to have a reference field on the sys_user table that holds the value of the RITM. The script would then take the parent.request_item.sys_id from the SCTASK and compare it to the RITM field on the user record. I think if you didn't have that, the GlideRecord might balk and just return the first thing it comes to.
Could you share your code?