Need to update alm_asset table fields

akila reddy
Tera Contributor

Hi all, i have  a requirement to update fields in alm asset table. There is a field call refresh date in the form, i have to update whatever the refresh date given in the form to the refresh date in cmdb table and also update status to in use and substatus to pending decommission. I'm able to update cmdb with refresh date but not able to update alm asset table fields. Please help me with the script.

var ci = current.variables.select_device_to_refresh;
var planned_referesh_date = current.variables.enter_planned_refresh_date_user_might_have_other_preference;
 
assetReturn();
 
function assetReturn() {
 
    var asset = new GlideRecord('cmdb_ci');
    asset.addQuery('sys_id', ci);
    asset.query();
    if (asset.next()) {
        //gs.log('akila');
        asset.u_refresh_date = planned_referesh_date;
        
 
       var asset1 = new GlideRecord('alm_hardware');
 
if(asset1.get('u_refresh_date',current.variables.enter_planned_refresh_date_user_might_have_other_preference)){
 
asset1.install_status = '1';
 
asset1.substatus = 'On Loan';
 
asset1.update();
}

 

1 REPLY 1

Manmohan K
Tera Sage

Hi @akila reddy 

 

The get method you are using to retrieve hardware asset will only work if refresh date is unique across the table

It would be better to use addQuery instead. Please test with below script  - 

 

var ci = current.variables.select_device_to_refresh;
var planned_referesh_date = current.variables.enter_planned_refresh_date_user_might_have_other_preference;
 
assetReturn();
 
function assetReturn() {
 
    var asset = new GlideRecord('cmdb_ci');
    asset.addQuery('sys_id', ci);
    asset.query();
    if (asset.next()) {
        //gs.log('akila');
        asset.u_refresh_date = planned_referesh_date;
        asset.update();
        }
 
       var asset1 = new GlideRecord('alm_hardware');
 
asset1.addQuery('u_refresh_date',current.variables.enter_planned_refresh_date_user_might_have_other_preference);
asset1.query();
while(asset1.next())
 {
asset1.install_status = '1';
 
asset1.substatus = 'On Loan';
 
asset1.update();
}}