Update the value based on the selected assets on the alm_hardware table

vinuth v
Tera Expert

Hi All,

 

I need to update the selected values from the multirow variable set to alm_hardware record.

 

I tried with the normal variable like this

vinuthv_0-1690788932035.png

vinuthv_1-1690788949242.png

 

The below code is working fine for the both the options.

current.approval="Approved";
var abc;
var worknotes="work_notes";
var Request=current.variables.request_type;
var Commment=current.variables.comments;
var state=current.variables.state;
var stockroom1=current.variables.stockroom;
var substate=current.variables.substate;
var assignedto=current.variables.assigned_to;
var assigned=current.variables.assigned;
abc= current.variables.assets;
 
var ass = current.variables.asset_to_update;
var gr1 = new GlideRecord('alm_hardware');  
gr1.addQuery('sys_id',ass);
gr1.query();
if(gr1.next()){
if(current.variables.reason_for_update == 'I want to update the asset state'){
gr1.install_status = '6';
gr1.substatus = substate;
}
else if(current.variables.reason_for_update == 'I want to update the asset assignment'){
gr1.assigned_to=assignedto;
gr1.assigned=assigned;
}
gr1[worknotes].setJournalEntry(Request+" "+ "-"+" "+Commment);
gr1.update();
}

 

 

But when the Reason for update is "I want to update the asset state" I have created the multirow variable set instead of normal variables. My query is I need to update the selected values on the alm_hardware record.

vinuthv_2-1690789053341.png

 

For this I tried with the below script,


var abc;
var worknotes="work_notes";
 
var Request=current.variables.request_type;
var Commment;
abc=current.variables.asset_to_update_s;     // variable set name
var multiRowSet = [];
var array=[];
var ass;
var sub;
multiRowSet.push(abc);
multiRowSet = JSON.parse(multiRowSet);
workflow.scratchpad.assetlength= multiRowSet.length;
for (var i = 0; i < multiRowSet.length; i++) {
 array.push(multiRowSet[i].v_asset_3);
ass = multiRowSet[i].v_asset_3;
sub = multiRowSet[i].v_substate_3;
Commment = multiRowSet[i].v_comments_3;
gs.log("asssub30" + i + multiRowSet[i].v_asset_3+"/"+multiRowSet[i].v_substate_3);
var gr1 = new GlideRecord('alm_hardware');  
gr1.addQuery('sys_id',multiRowSet[i].v_asset_3);
gr1.query();
if(gr1.next()){
if(current.variables.reason_for_update == 'I want to update the asset state'){
    gr1.install_status = '6';
       gr1.substatus = sub;
gr1[worknotes].setJournalEntry(Request+" "+ "-"+" "+Commment);
 
gr1.update();
gs.log("statestate44");
}
else if(current.variables.reason_for_update == 'I want to update the asset assignment'){
  gr1.assigned_to=assignedto;
  gr1.assigned=assigned;
  gr1[worknotes].setJournalEntry(Request+" "+ "-"+" "+Commment);
  gr1.update();
}
}
}
 
Note: When Reason for update is "I want to update the asset assignment" using normal variables like below
vinuthv_3-1690789361194.png

 

Please any one provide me the inputs,

 

Thanks in advance,

Vinuth

 

 

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@vinuth v 

So what's your analysis after debugging?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader