HELP!! How to update target record when record is not in external data source

Mike D1
Giga Guru

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

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

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'};
}

View solution in original post

3 REPLIES 3

Tony Chatfield1
Kilo Patron

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'};
}

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?

 

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.