Want to update the records in alm_asset table not to restrict when a record producer is submitted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 09:53 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 10:11 PM
Hi, I think you need to utilize your record producer script, rather than using a BR.
Run a suitable glidequery in your producers script.
If a record match is found, update fields of the existing record as appropriate, then abort the record producer insert.
If a match is not found continue with the record producer insert.
I think you already have most of your code in your BR and just need to relocate it to the producer and tweak it a touch.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 10:18 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 10:50 PM
As indicated above you already have most of your code, but here are some options for your record producer script
var grDupCheck = new GlideRecord('alm_asset');
grDupCheck.addQuery('serial_number', producerSerialNumberField).addOrCondition('asset_tag',producerAssetTagField);
grDupCheck.query();
if (grDupCheck.next()) {
//update fields for existing record if required
//If you only want to update only if specific conditions are met, use a variable to decide when to update
var makeAnUpdate = false;
//Example update Serial number if different, but asset tag is same
if(producerSerialNumberField != grDupCheck.serial_number) {
grDupCheck.serial_number = producerSerialNumberField;
makeAnUpdate = true;
}
//Otherwise update any field on the existing record, but 'grDupCheck.update()' will need to be outside of the makeAnUpdate conditon check
grDupCheck.someField2 = someProducerValue2;
if(makeAnUpdate == true) {
grDupCheck.update();
}
gs.addErrorMessage("Serial number or asset tag already exists, so new record insert aborted");
current.setAbortAction(true);
} else {
//Run your existing record producer script so that a new record is created and populated
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 10:22 PM
@Community Alums
you want to update via record producer?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader