Auto populate the current users laptop in a catalog item

Moedeb
Tera Guru

I have a reference field on alm_asset and I just want to show in that field (on load) the current users assigned laptop.

So for us laptops all have a model category of 'Computer', so I'd tried to set the default value of the field as follows:

Variable name: vs_laptop_asset_number

Table: alm_asset

Asset model category 'Computer' sys_id: 81feb9c137101000deeabfc8bcbe5dc4

Asset assigned user field name: owned_by

 

Default value:

javascript:model_category=81feb9c137101000deeabfc8bcbe5dc4^owned_by=gs.getUserID();

 

This obviously has not worked as I'm asking all of you for some help please

1 ACCEPTED SOLUTION

@Moedeb 

 

In that case, you can may be populate the asset owned as per the asset table in one variable which could be read only and have a confirmation checkbox stating "Does the above listed asset does not belongs to you ?". If the user response is yes, you can have a variable for them to select the asset.

 

Let me know your thoughts on this and we can further work it towards closure.


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

24 REPLIES 24

Hello @Moedeb 

 

Choose an Appropriate Role:

Select one of the following roles based on your needs:

  • itil: If you want this script to be callable only by ITIL users.
  • admin: If you want this to be restricted to admin users.
  • x_your_app_user: If you have custom roles for your application, you can use those.
  • No role (optional): If you leave the role empty, any user will be able to call the Script Include. This is not recommended for security reasons unless you specifically intend it to be publicly accessible.

@Juhi Poddar I really need this to be something that all our users can search, as I've said unfortunately we cannot be 100% sure that all assets are assigned accurately, therefore we need our users to be able to search potentially for the correct asset number after presenting them with the one we have recorded for them.

So the best option role wise would be to leave it blank, however ServiceNow doesn't allow that for the client callable script include, they require a role to be selected.

 

I selected 'public' as we have a protected ServiceNow instance and only our internal staff have access anyway, however this still does not populate the field with an asset.

Sumanth16
Kilo Patron

Hi @Moedeb ,

 

First, in default value on the variable enter: javascript:getPrimaryAsset();



Then create a Script Include like this:



Name: getPrimaryAsset

 

Client Callable: checked



Script:

 

function getPrimaryAsset(){



  var usr = gs.getUserID().toString();

 

  var asset = new GlideRecord('u_cmdb_ci_ubf_inv'); //change to your ci/asset table

 

  asset.addQuery('assigned_to', usr);

 

  asset.addQuery('operational_status', '5');

 

  asset.orderByDesc('sys_updated_on');

 

  asset.query();

 

  if(asset.next()){

 

  //gs.log('DEBUG: getPrimaryAsset, return: ' + asset.sys_id.toString); // for test

 

  return asset.sys_id.toString();

 

  }

 

  else

 

  return '';

 

}



This will get a list of the user´s computers/devices and sort them in descending date order (latest updated first).

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

 

This doesn't really assist as not all users have their laptops set as primary assets

Amit Verma
Kilo Patron
Kilo Patron

Hi @Moedeb 

 

While configuring the VS Laptop Asset Number variable, you can make use of a Simple Reference Qualifier condition as shown below :

AmitVerma_0-1728966235626.png

 

AmitVerma_1-1728966287590.png

 

As you can see from above screenshot, I only own one asset so in the catalog item, I will only be allowed to select the assets owned by me, in this case, this single asset only.

AmitVerma_2-1728966378803.png

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.