Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Check for empty field when performing transform

Lee Taylor
Kilo Contributor

Hi,

We have a number of data sources within my organisation and we are currently performing manual load & transforms.  I would like to have some fields updated based on one of the target fields being empty.

This is my script

//Verify that Discovery Source is not empty

if(!target.discovery_source.isnil()) {

target.discovery_source = 'EO Master Sheet';
target.first_discovered = gs.nowDateTime();
target.last_discovered = gs.nowDateTime();

} else {

//If not empty then set Last Discovered to today

target.last_discovered = gs.nowDateTime();

}

 

If anyone can shed any light into where I am going wrong, it would be much appreciated.

 

Regards
Lee

5 REPLIES 5

Jaspal Singh
Mega Patron

Hi Lee,

 

Try using below snippet.

if(!target.discovery_source.isNil()) {

target.discovery_source = 'EO Master Sheet';
target.first_discovered = gs.nowDateTime();
target.last_discovered = gs.nowDateTime();

} 

else {

//If not empty then set Last Discovered to today

target.last_discovered = gs.nowDateTime();

}

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

Hi Jaspreet,

 

Many thanks for your swift response.

 

I have reformatted my script as per the above, however it is still having the same issue:

 

When the transform runs, regardless of whether the discovery source field has a value, it updates the First Discovered & Last Discovered fields, it should only update the Last Discovered field if there is a value.

 

Regards
Lee

If I recall, isNil() is a Java method. Try using nil() instead.

if (!target.discovery_source.nil()) {
  target.discovery_source = 'EO Master Sheet';
  target.first_discovered = gs.nowDateTime();
  target.last_discovered = gs.nowDateTime();
} else {
  //If not empty then set Last Discovered to today
  target.last_discovered = gs.nowDateTime();
}

Lee Taylor
Kilo Contributor

Thanks Chuck,

Amending to nil() didn't resolve it on it's own, but when I looked at that line I removed the ! and that, plus the nil() did the job.

 

Many thanks
Lee