Onbefore Transform map not updating the record, only inserting even though matches with theCondition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 12:47 PM - edited 07-01-2024 12:47 PM
Following is my field map
following is onbefore script
here I am checking if entity and current_ram combination exits, if yes then update the record.
I am mapping ram with the expected ram
if combination does not exits then create new record
for reference this is the table and following is the form
Following is the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 08:40 PM
try using this script"
var entityName = source.u_entity;
var currentRAM = source.u_current_ram;
// Create a new GlideRecord instance for the target table
var up = new GlideRecord("sn_risk_advanced_risk_assessment_scope");
// Add query to find records where entity name and risk assessment methodology match
up.addEncodedQuery("entity.nameSTARTSWITH" + entityName + "^risk_assessment_methodology.nameSTARTSWITH" + currentRAM);
up.query();
// If the record exists, update it
if (up.next()) {
// Map the existing record fields to the target object to perform the update
target.initialize();
for (var field in source) {
if (source.hasOwnProperty(field) && target.isValidField(field)) {
target[field] = source[field];
}
}
target.setWorkflow(false); // Disable business rules and workflows
target.autoSysFields(false); // Prevent automatic updating of sys fields like sys_updated_by and sys_updated_on
target.update(); // Save the changes
action == 'update';
}
// Else, ignore the record creation
else {
ignore = true;
}
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 10:56 PM
Hi @Deepak Shaerma ,
target.update I can not use, they are having their best practice set while saving the code, throws error message target.update can not be used in onbefore