Transform Map - do not update target field if already populated

Steven Watts2
Tera Guru

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

4 REPLIES 4

Harish Bainsla
Kilo Patron
Kilo Patron

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);

Hi @Harish Bainsla 

 

Thanks for the response, unfortunately I get the same result I.e., the Support group value is still empty on the target record.

 

Steven

Jim Coyne
Kilo Patron

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.

 

How can this work if there is no terget defined? The function is only called with source.