Record Producer Will Not Update Existing Record - Only Create New Record

chrisinhoff
Tera Contributor

Hello,

 

I am trying to create a workflow/form in ServiceNow, where the form has about 6 questions.

What Configuration Item would you like to modify?

Then I have like 5 questions like Serial Number, Location, and MAC Address available to enter details.

I have tried using a Catalog Item to do this, but I have had no luck in trying to get the selected CI to be recognized by the flow.

I then tried a Record Producer, but it seems to only want to create a new record, and not modify an existing one, no matter what I do.

Is a Record Producer supposed to be able to modify existing records? This seems like it would be an easy thing to set up.

5 REPLIES 5

chrisinhoff
Tera Contributor

I have gotten this to work. Thanks for all the help. Below is the code I used:

var selectedCiSysId = producer.cmdb_ci; // Selected CI from cmdb_ci

var asset = new GlideRecord('alm_asset');
asset.addQuery('ci', selectedCiSysId); // Find asset linked to the selected CI
asset.query();

if (asset.next()) {
    // Update only if the asset exists
    asset.install_state = producer.install_status;
    asset.location = producer.cmn_location;
    asset.serial_number = producer.serial_number;
    asset.mac_address = producer.mac_addr;
    asset.assigned_to = producer.assigned_to;
   
    asset.update();
    gs.addInfoMessage("Asset updated successfully.");
   
    current.setAbortAction(true); // Prevents new record creation
} else {
    gs.addErrorMessage("No asset found linked to the selected CI.");
}