Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions GlideAjax/Return Asset(s) for User/FindUserAsset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
var getUserAsset = Class.create();
getUserAsset.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

///////////////////////////////////////////////////////////////////////////////////////////////////////Return 1 Asset Any Model//////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

getOneAsset: function() {

var userSys = this.getParameter('sysparm_user');

var mAsset = new GlideRecord('alm_hardware');
mAsset.addQuery("assigned_to", userSys);
mAsset.setLimit(1);
mAsset.query();
while (mAsset.next()) {
var astID = mAsset.sys_id;
}
return astID;

},

/////////////////////////////////////////////////////////////////////////////////////////
//////////////////////Return 1 with specific Model Category////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

getAssetCustom: function() {

var userSys = this.getParameter('sysparm_user');
var astCat = this.getParameter('sysparm_category');

var mAsset = new GlideRecord('alm_hardware');
mAsset.addEncodedQuery('model_category=' + astCat + '^assigned_to=' + userSys);
mAsset.setLimit(1);
mAsset.query();
while (mAsset.next()) {
var astID = mAsset.sys_id;
}
return astID;

},

/////////////////////////////////////////////////////////////////////////////////////////
///////// Reutns All Assets for User////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

getAllAssets: function() {

var userSys = this.getParameter('sysparm_user');
var aList = [];

var mAsset = new GlideRecord('alm_hardware');
mAsset.addQuery("assigned_to", userSys);
mAsset.setLimit(20); //Set Limi to 20 to prevent too many returns in case of a generic account/blank account is passed.
mAsset.query();
while (mAsset.next()) {
alist.push(mAsset.sys_id);
}
return aList;

},


type: 'getUserAsset'
});
9 changes: 9 additions & 0 deletions GlideAjax/Return Asset(s) for User/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Client Callable GlideAjax script include to return one of the Following based on passed user's sys_id:

-Single Asset for User

-Single Asset for User with Model Category filtering

-All Assets for User

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.