IS NULL / no value

Added by Steven Schreuder almost 2 years ago

Hi forum,

I have a question about setting a condition context.
My goal: I have a date field in my source data. If there is data (a date) in the field I want it to be entered in the target schema. If the data is empty (no date is entered in the source) I would like to enter the date of today.

My idea was to enter a condition context "value <> ''" and map that (rename). Add another condition context "value IS NULL" and put that in a Bound Assign.
I seem to fail in this. The IS NULL seems not to work. I also tried "value = ''" or "value = 'no value'" I also tried parent.fieldname IS NULL.

Tips are very welcome.

Cheers,
Steven


Replies (6)

RE: IS NULL / no value - Added by Simon Templer almost 2 years ago

Hi Steven,

a condition is only evaluated on an element that is present. Thus an "is null" for a property can only be used on a parent element (e.g. a type).

To achieve what you want to do you can use one relation with low priority providing a default value (e.g. an Assign or in your case a simple Groovy script with new Date()) and a second relation with a higher priority that maps the source value.

Best,
Simon

RE: IS NULL / no value - Added by Steven Schreuder almost 2 years ago

Hi Simon,

Thanks for the tips! The new Date is very usefull.
I can't seem to get the other tip right, however.
I used a Groovy script to assign a new Date to a targetfield. And a rename on the sourcefield to populate the targetfield whenever data is present.

I have enclosed a sample project (type 'duiker') in which I have tried two options on two different (non-nillable) fields.

Regards, Steven

RE: IS NULL / no value - Added by Simon Templer almost 2 years ago

Hi Steven,

the mapping itself looks ok to me. I can't really test with it, as the .hale file does not include the target schema and data. Can you maybe provide the project as hale project archive (.halez) and describe what's the remaining problem?

Best regards,
Simon

RE: IS NULL / no value - Added by Steven Schreuder almost 2 years ago

Thanks for your effort, Simon!
Attached a zip file with the sample data (duiker), a hale file and the target schema's (my workspace was to big to export...)

I tried to make the mapping like this:
If there is a date entered in the beginlifes field it should be mapped to a target datefield. When there is no date entered, the target datefield should be filled with the current date.
In my mapping I tried with both higher or lower priority for the groovy script. But both options give the wrong result. High priority leads to only the groovy script being executed, low priority doesn't execute the groovy script at all.

Best regards,
Steven

samples.zip (719.7 kB)

RE: IS NULL / no value - Added by Simon Templer almost 2 years ago

Hi Steven,

the Groovy script should have the low priority, that's the right approach.

When I open your example there are values for beginlifes in all duiker_lines. You can see that in hale in the schema explorer based on the instance numbers - there are 4679 duiker_lines and of those 4679 have a value for beginlifes.

If you look at the properties of beginlifes and there calculate the occurring values, you see what values there are. There is nothing that looks to me like it is an obvious kind of "no value".

What kind of value would you expect for your duikers that have no information on beginlifes?

Best,
Simon

sample_duiker.halez - Project archive w/ only duiker data and mapping (701.2 kB)

RE: IS NULL / no value - Added by Steven Schreuder almost 2 years ago

Hi Simon,

When I look at the source data (either in the source data tab or by opening the dbf-file belonging to the shape) I see 'no value' mentioned in several features. Als when you sum the concurring values (multiplied by the number between bracjets) it only gives 2567 values. So there are about 2000 'empty' dates.

I really appreciate all the help you are giving.

Regards,
Steven

(1-6/6)