- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 01:28 PM
Hi
I am wanting to know how I can update a field on an existing target record when the record does not exist in the data source?
How can this be achieved in transform script? Something like my pseudo code below:
if (record doesn't exist in source && record exists in target) {
target.xxx = "foo"
}
Thanks
Mike
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 01:42 PM
Hi, a before transform script will run for every row of your import set/file and depending on your configuration\file content, one of these should work.
//Check if the field exists
if(typeof source.field != 'undefined') {
target.field = source.field;
} else {
log.info('source.field does not exist'};
}
//Check if the field has content
if(source.field != '') {
target.field = source.field;
} else {
log.info('source.field is empty'};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 01:42 PM
Hi, a before transform script will run for every row of your import set/file and depending on your configuration\file content, one of these should work.
//Check if the field exists
if(typeof source.field != 'undefined') {
target.field = source.field;
} else {
log.info('source.field does not exist'};
}
//Check if the field has content
if(source.field != '') {
target.field = source.field;
} else {
log.info('source.field is empty'};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 03:35 PM
Thanks for the reply Tony.
I have tried your suggestion of onBefore transform script, however it did not work.
As the records don't exist at all in the source (it's not just the field "install_status" that doesn't exist/empty) I selected the coalesce field "serial number" as source.....
//Check if record exists
if(typeof source.u_serialnumber != 'undefined') {
target.install_status = 'sys_id of status';
} else {
target.install_status = 'sys_id of other status';
}
//Check if the field has content
if(source.u_serialnumber != '') {
target.install_status = 'sys_id of status';
} else {
target.install_status = 'sys_id of other status';
}
Not sure if you see anything wrong here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 12:36 PM
I had to create a scheduled job in the end to change state of all records and then was able to use before transform to check source field. Don't know if it is the most efficient way but it works.