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.

Unable to set value in stockroom field from a staging form

pabitras
Giga Contributor

Hi Team,

Facing issues while passing value to this field from a custom staging form's u_stockroom reference field I am trying to pass through a glide record insert, but it's not setting and being blank. Please see below code snippet:-

var stock = new GlideRecord('alm_asset');

stock.addQuery('serial_number', dataRows.serial_number);

stock.queryNoDomain();

//gs.addInfoMessage('Before If Stockroom');

if(stock.next()){

stock.stockroom.value = current.u_stockroom;

stock.update();

gs.addInfoMessage('Inside If Stockroom');

}

Somewhere I read someone said   in this thread:- How to import XLS data to Stockroom   :- 4) try to figure how to link the assets to the stockroom (the field Stockroom on the asset table seems interesting :))

Can you or someone please put some light on it.

Thanks,

Pabitra

6 REPLIES 6

pabitras
Giga Contributor

Hi There,



Actually from a staging form, we have a transformation script to trigger a mapping and there is one Business Rule runs insert/update on this staging form, to check and create/update the Asset with all necessary details like IMEI, Serial Number, etc from file, and stockroom from staging form where user selects manually.



var stock = new GlideRecord('alm_asset');


stock.addQuery('serial_number', dataRows.serial_number);


stock.query();


if(stock.next()){


stock.stockroom = current.u_stockroom; // Both are reference fields points to alm_stockroom table.


stock.update();


}



Thanks,


Pabitra


Hi Pabitra,



There is a onBefore business rule ("Reset Stockroom") which is setting stockroom value to blank if the below conditions are not matching :



Screen Shot 2017-09-18 at 10.09.46 PM.png


Hi Chirag,



Thanks for your reply and finding. But I tried to disable this BR, still it's not setting up anything in Stockroom field. And also I am also passing In Stock and Available as Status and Sub Status in device record.



Could be something else...



Actually there is a table to which I am inserting/update the data "u_cmdb_ci_hardware_user_device" which is inherited from alm_asset and when I try to create a new device manually and set Stockroom, it gets cleared and then it becomes read only as per some property set for this field. So to update stockroom need to open the asset record either from alm_asset or alm_hardware table and save the value to reflect back in child table mentioned above.



Thanks again,


Pabitra


Thanks.



Can you check "Create Stockroom Model Relation" business rule ? I think, that is stopping you.