How do I update a record from a Service Catalog item using a record producer?

nomadie
Kilo Expert

I have created a catalog item using a record producer that displays list of fields from our asset table. Users can use this catalog item to update the field/s and when submitted, those changes/new values will now reflect on the asset table.

Appreciate any advise from the gurus here. TIA.

1 ACCEPTED SOLUTION

Jace Benson
Mega Sage

There some great past posts about doing this;

https://community.servicenow.com/community?id=community_question&sys_id=e9bb4ba1db9cdbc01dcaf3231f96...

Pertinent info;

// So the record Producer Script would be something like this where you have the user 
// entering in an incident number to update the description on an incident 
// (variables:   u_incident, comments):

var incGR = new GlideRecord("incident");
if (incGR.get(producer.u_incident)){//if you found an incident
incGR.description += producer.comments;
incGR.update();
}
current.setAbortAction(true);   //this aborts the Record Producer from creating a new 
// incident if you set the Record Producer table to incident.

View solution in original post

2 REPLIES 2

Jace Benson
Mega Sage

There some great past posts about doing this;

https://community.servicenow.com/community?id=community_question&sys_id=e9bb4ba1db9cdbc01dcaf3231f96...

Pertinent info;

// So the record Producer Script would be something like this where you have the user 
// entering in an incident number to update the description on an incident 
// (variables:   u_incident, comments):

var incGR = new GlideRecord("incident");
if (incGR.get(producer.u_incident)){//if you found an incident
incGR.description += producer.comments;
incGR.update();
}
current.setAbortAction(true);   //this aborts the Record Producer from creating a new 
// incident if you set the Record Producer table to incident.

Hi @jacebenson thank you for this.. I tried using this one, however, whenever I run the catalog item and query, the page is frozen.

//This will prevent the record producer from creating a new record.
current.setAbortAction(true);

var hwasset = new GlideRecord("alm_asset");
if ((hwasset.get(producer.asset_tag)) || (hwasset.get(producer.serial_number))){
hwasset.install_status += producer.install_status; //if you found a record, update
hwasset.update();
}

//This will redirect to the portal
producer.redirect = "catalog_home.do?sysparm_view=catalog_default";