How can i get assets assigned to a user in esc portal
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 09:59 PM
Hi all,
we have a requirement where we need to get details of asset assigned to a user.
For this i created a list field on user table (u_test_asset) -> why list field means in computer table, for a single user there are multiple records so i created list field.
And I wrote after BR (insert/update) on computer table
condition: assigned to changes and assigned to is not empty.
********************
(function executeRule(current, previous /*null when async*/ ) {
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id', current.assigned_to);
userGR.query();
while (userGR.next()) {
//gs.addErrorMessage("line7" +current.getDisplayValue('asset'));
var arr = [];
var gr = new GlideRecord('cmdb_ci_computer');
gr.addQuery('assigned_to',userGR.sys_id);
gr.query();
while(gr.next()){
//gs.addErrorMessage("inside while");
//gs.addErrorMessage("asset");
var tt = gr.getDisplayValue('asset');
//gs.addErrorMessage("tt" +gr.getDisplayValue('asset'));
var test = arr.push(gr.getDisplayValue('asset'));
}
userGR.u_test_asset= arr.join(',');
//userGR.u_test_asset = gr.getDisplayValue('asset');
userGR.update();
}
})(current, previous);
************************************
the above code works fine and ow the requirement was changed... the user is asking to view like below..
Show the Asset information as a table with the following information:
Class - Model ID - Serial Number
Class - Model ID - Serial Number
Now i think list field i created on user table is not useful.
I am thinking to take a string field and should display the data.. but if one user have 2 model id's then the record should come in next line
for eg: if user A has two asstes; the data should display in custom field like below
classa - modela - seriala
classb - modelb - serialb
Can someone suggest how can i achieve this..
Thankyou !
0 REPLIES 0