How to update a target field without coalesce in transform map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2022 09:25 AM
Hi
I want to update an active field in target table if business area is XYZ, I tried the code below but it is inserting a new record instead of updating existing record
var resGrp1 = new GlideRecord('restricted_groups');
resGrp1.addQuery('group_id', source.u_group_number);
resGrp1.addQuery('business_area', XYZ);
resGrp1.addQuery('active', false);
resGrp1.query();
if(resGrp1.next()){
resGrp1.active = true;
resGrp1.update();
can anyone help me on this, Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2022 10:04 AM
Hi @Dharma5
You can create a field mapping for Active field with Source Script as below:
Find the same code below:
var resGrp1 = new GlideRecord('restricted_groups');
resGrp1.addQuery('group_id', source.u_group_number);
resGrp1.addQuery('business_area', 'XYZ');
resGrp1.addQuery('active', false);
resGrp1.query();
if (resGrp1.next()) {
return true;
} else {
return false;
}
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2022 04:15 PM
Hi Anubhav,
Thanks for the reply.
But we cannot use field map script here for active field. Because we’re not mapping active field, we want to update it through some validations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2022 11:35 PM
Hi @Dharma5
Than you can write below code in Transform Script as onAfter:
var resGrp1 = new GlideRecord('restricted_groups');
resGrp1.addQuery('group_id', source.u_group_number);
resGrp1.addQuery('business_area', 'XYZ');
resGrp1.addQuery('active', false);
resGrp1.query();
if (resGrp1.next()) {
target.active = true;
} else {
target.active = false;
}
target.update();
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 03:01 AM
I tried writing that script in onAfter, it is making old record in target table to true but it was again creating a new record and we need to avoid that(creating new record in target table).