Transform Map - do not update target field if already populated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 02:08 AM
Hi,
I'm trying to get a transform map entry to not process a field value update if the target record already contains a value. Reason for this is that the field in question is mandatory on insert so we're setting a default value. What we don't want though is that default value to overwrite the existing value if present.
Source script is below.
If the support group value on the target record is not empty ignore the update, otherwise set the value to the default.
answer = (function transformEntry(source) {
var supportGroup = gs.getProperty("snow_software_group");
if (JSUtil.notNil(target.support_group))
ignore = true;
else {
return supportGroup;
}
})(source);
The computer records being tested are not having their support group value updated even though it's currently empty. Anyone see where I'm going wrong?
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 02:20 AM
try this
answer = (function transformEntry(source) {
var supportGroup = gs.getProperty("snow_software_group");
if (JSUtil.notNil(current.support_group))
ignore = true;
else {
source.support_group = supportGroup; // Set the default value
}
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 02:30 AM
Thanks for the response, unfortunately I get the same result I.e., the Support group value is still empty on the target record.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2023 11:49 AM - edited ‎08-29-2023 11:51 AM
Here's how you can do it:
answer = (function transformEntry(source) {
//default value from the System Property
var result = gs.getProperty("snow_software_group");
//is there already a value in the record?
if (action == "update" && !target.support_group.nil()) {
//let's keep it then
result = target.getValue("support_group");
}
return result;
})(source);
The logic will set any existing records WITHOUT an Approval group to the same as the System Property. That does not seem likely though if the field is mandatory as you mentioned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2023 06:57 AM
How can this work if there is no terget defined? The function is only called with source.