Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Script include to filter Assets based on field value

Community Alums
Not applicable

Hi Experts,
On the asset_task table,I have one field called action when action is assign> in asset field I need to populate only the assets which are in Instock state,  and when the action is return I need to populate the assets which are assigned for the requested for user on task form.So I have tried the below script include and reference qualifier for action== assign ,but it is not working.it is returning only one value.

but for return reference qualifier is working fine
Please help me on this.


Script include:

var get_assets = Class.create();
get_assets.prototype = {
    initialize: function() {
    },
 
 
getAssetDetail: function() {
        var assetArray = [];
       
        var asset = new GlideRecord('alm_asset');
        asset.addEncodedQuery('install_status=6');
 
        asset.query();
        while (asset.next()) {
            assetArray.push(asset.sys_id);
        }
        return 'sys_idIN' + assetArray.join();
    },
 
    type: 'get_assets'
};
 
Reference qualifier:
javascript: if(current.u_action== 'assign') new get_assets().getAssetDetail(); if(current.u_action== 'return')"assigned_to=" + current.requested_for
 
and I have tried the other reference qualifier aslo without script include.
javascript: if(current.u_action== 'return')"assigned_to=" + current.requested_for;if(current.u_action== 'assign') install_status=6^EQ

 
Thanks in advance,
Chaithanya

 

1 ACCEPTED SOLUTION

Hello Chaithanya,

 

Use below qualifier :

 

javascript: "install_status=6^stockroom=" + current.getValue('stockroom');

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

3 REPLIES 3

Vishal Birajdar
Giga Sage

Hello @Community Alums 

 

Assuming "asset" field is referencing to "alm_asset" table.

 

can you please use "configure dictionary " option and set directly simple reference qualifier

 

VishalBirajdar7_0-1693999764262.png

 

 

If you want to use advance reference qualifier then directly put query

 

VishalBirajdar7_1-1693999922779.png

 

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Community Alums
Not applicable

Hi @Vishal Birajdar 
Thanks for the reply!

and need one more help on the same,

CHAITHANYA13_0-1694010405468.png

now I need to populate the assets based on the stockroom also, which are all the assets are there in that stockroom where asset state is "in stock"
I have tried below Reference qualifier. but not working
javascript: "install_status=6"^"stockroom=" + current.stockroom

Hello Chaithanya,

 

Use below qualifier :

 

javascript: "install_status=6^stockroom=" + current.getValue('stockroom');

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates