Check for empty field when performing transform
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2018 11:19 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2018 12:05 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2018 04:46 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2018 05:04 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2018 06:46 AM
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