Skip to content

Commit f8f070f

Browse files
authored
Return user asset util (ServiceNowDevProgram#729)
1 parent 5d13efe commit f8f070f

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
var getUserAsset = Class.create();
2+
getUserAsset.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
3+
4+
///////////////////////////////////////////////////////////////////////////////////////////////////////Return 1 Asset Any Model//////////////////////////////////////////////////////
5+
/////////////////////////////////////////////////////////////////////////////////////////
6+
7+
getOneAsset: function() {
8+
9+
var userSys = this.getParameter('sysparm_user');
10+
11+
var mAsset = new GlideRecord('alm_hardware');
12+
mAsset.addQuery("assigned_to", userSys);
13+
mAsset.setLimit(1);
14+
mAsset.query();
15+
while (mAsset.next()) {
16+
var astID = mAsset.sys_id;
17+
}
18+
return astID;
19+
20+
},
21+
22+
/////////////////////////////////////////////////////////////////////////////////////////
23+
//////////////////////Return 1 with specific Model Category////////////////////////////
24+
///////////////////////////////////////////////////////////////////////////////////////
25+
26+
getAssetCustom: function() {
27+
28+
var userSys = this.getParameter('sysparm_user');
29+
var astCat = this.getParameter('sysparm_category');
30+
31+
var mAsset = new GlideRecord('alm_hardware');
32+
mAsset.addEncodedQuery('model_category=' + astCat + '^assigned_to=' + userSys);
33+
mAsset.setLimit(1);
34+
mAsset.query();
35+
while (mAsset.next()) {
36+
var astID = mAsset.sys_id;
37+
}
38+
return astID;
39+
40+
},
41+
42+
/////////////////////////////////////////////////////////////////////////////////////////
43+
///////// Reutns All Assets for User////////////////////////////////////////////////////
44+
///////////////////////////////////////////////////////////////////////////////////////
45+
46+
getAllAssets: function() {
47+
48+
var userSys = this.getParameter('sysparm_user');
49+
var aList = [];
50+
51+
var mAsset = new GlideRecord('alm_hardware');
52+
mAsset.addQuery("assigned_to", userSys);
53+
mAsset.setLimit(20); //Set Limi to 20 to prevent too many returns in case of a generic account/blank account is passed.
54+
mAsset.query();
55+
while (mAsset.next()) {
56+
alist.push(mAsset.sys_id);
57+
}
58+
return aList;
59+
60+
},
61+
62+
63+
type: 'getUserAsset'
64+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Client Callable GlideAjax script include to return one of the Following based on passed user's sys_id:
2+
3+
-Single Asset for User
4+
5+
-Single Asset for User with Model Category filtering
6+
7+
-All Assets for User
8+
9+
Script queries the "alm_hardware" table. Intended to be called from a client script/catalog client script, one use case would be to populate a users asset on a catalog item form.

0 commit comments

Comments
 (0)