Want to update the records in alm_asset table not to restrict when a record producer is submitted.

Community Alums
Not applicable

Hi All, 

 

we are having a record producer to insert the records in alm_asset table. 

on the form there is a serial number filed. if we submit the form with the same serial number we need to update the record instead of restricting to insert. 

 

need suggestions. 

we tried with BR as below.

(function executeRule(current, previous /*null when async*/) {
 
var grDupCheck = new GlideRecord('alm_asset');
 
  grDupCheck.addQuery('serial_number', current.serial_number).addOrCondition('asset_tag',current.asset_tag);
 
  grDupCheck.query();
 
  if (grDupCheck.next()) {
 
  gs.addErrorMessage("Serial number or asset tag already exists");
 
  current.setAbortAction(true);
 
  }
})(current, previous);
 
 
Thanks.
8 REPLIES 8

Community Alums
Not applicable

@Ankur Bawiskar  Yes, once the request is submitted. 

 

Thanks.

@Community Alums 

so user will update which target record?

your record producer has which all variables?

If serial number present on variable is present you want to update which fields on target table?

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

@Community Alums 

something like this in record producer script

var grDupCheck = new GlideRecord('alm_asset');
grDupCheck.addQuery('serial_number', producer.serialNumberVariable).addOrCondition('asset_tag',producer.assetTagVariable);
grDupCheck.query();
if (grDupCheck.next()) {
	
	grDupCheck.field1 = producer.variable1; // give the field and variable
	grDupCheck.field2 = prodcucer.variable2; // give the field and variable
	grDupCheck.update();
	current.setAbortAction(true);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Community Alums
Not applicable

@Ankur Bawiskar 

 

we are using the below script to insert the records. 

 

current.u_record_producer = "9695de4587b455901c18ea0e8bbb350c";
(function() {
 
var rowsInt = producer.u_serial_number.getRowCount();
//gs.log('Asset count : '+ rowsInt);
 
for(var i = 0; i < rowsInt; i++) {
var grIncident = new GlideRecord('alm_hardware');
grIncident.initialize();
grIncident.setValue('serial_number', producer.u_serial_number.getRow(i).serial_number_1);
grIncident.setValue('company', producer.company);
grIncident.setValue('model', producer.model);
grIncident.setValue('model_category', producer.model.cmdb_model_category);
//grIncident.setValue('', producer.model.manufacturer);
grIncident.setValue('stockroom', producer.stockroom);
grIncident.setValue('po_number', producer.po_number);
grIncident.setValue('vendor', producer.supplier);
grIncident.setValue('cost_center', producer.cost_center);
grIncident.setValue('cost', producer.purchase_cost);
grIncident.setValue('owned_by', producer.owner);
grIncident.setValue('purchase_date', producer.purchase_date);
grIncident.setValue('warranty_expiration', producer.warranty_expiration_1);
grIncident.setValue('comments', producer.additional_comments);
grIncident.setValue('u_fixed_asset_number', producer.fixed_asset_number);
grIncident.setValue('u_actual_name', producer.getDisplayValue('model'));
grIncident.setValue('u_manually_uploaded',true);
 
 
grIncident.insert();
}
 
})();
 
while inserting itself need to check if the same serial number is inserting then need to update the record in alm_hardware table. 
 
 
Thanks.