cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Super User
Super User

IF NULL: This should be easy!!

Not sure why this doesn't work. Can you spot the issue?

I just want to check if the timestamp coming across ("Observation_Date_Time") is null or not. If its null, write "1970-1-1 00:00:00", otherwise convert the timestamp from unix to human readable.

Works fine without the IF statement. "Invalid Expression" error with the IF. 

if(
    items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time']
    = null, //also tried = 0 //same error "invalid expression"
    '1970-1-1 00:00:00',
    addseconds(
        '1970-1-1',
        Div(
            items(
                'For_each_childRecord')?
                ['attributes']?
                ['Observation_Date_Time'],
            1000
        ),
        'yyyy-MM-dd hh:mm:ss'
    )
)  

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Dual Super User
Dual Super User

Re: IF NULL: This should be easy!!

Hi @ericonline 

 

and what about

 

equals(items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time']
    ,null)

equals(items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time']
    ,'')

View solution in original post

10 REPLIES 10
Super User
Super User

Re: IF NULL: This should be easy!!

@ericonline
Have you tried checking for an empty string? Try two single quotes and it may work

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Super User
Super User

Re: IF NULL: This should be easy!!

Hi @ScottShearer 

Just pasted this in:

if(
    items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time']
    = '',
    '1970-1-1 00:00:00',
    addseconds(
        '1970-1-1',
        Div(
            items(
                'For_each_childRecord')?
                ['attributes']?
                ['Observation_Date_Time'],
            1000
        ),
        'yyyy-MM-dd hh:mm:ss'
    )
)

Results:

image.png

Dual Super User
Dual Super User

Re: IF NULL: This should be easy!!

Hi @ericonline 

 

write a compose action and check output for 

items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time']

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Dual Super User
Dual Super User

Re: IF NULL: This should be easy!!

Hi @ericonline 

 

you can also try

 

empty(items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time'])

which should return a true or a false 

Super User
Super User

Re: IF NULL: This should be easy!!

Hi @RezaDorrani ,

 

The Compose action for the null record yeilds:

Note: All non-null Observation_Date_Time records showed the Unix time value

image.png

Clicking the link opens a blank browser window. Right click/view source, no content on the page. 

Dual Super User
Dual Super User

Re: IF NULL: This should be easy!!

@ericonline 

 

perfect now try

 

equals(items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time']
    ,null)

empty(items( 'For_each_childRecord')? ['attributes']? ['Observation_Date_Time'])

 

In compose actions to see the results

Super User
Super User

Re: IF NULL: This should be easy!!

@RezaDorrani 

 

`empty()` failed all records in the Flow. 

 

Tried:

if(
    empty(
    items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time']
    ),
    '1970-1-1 00:00:00',
    addseconds(
        '1970-1-1',
        Div(
            items(
                'For_each_childRecord')?
                ['attributes']?
                ['Observation_Date_Time'],
            1000
        ),
        'yyyy-MM-dd hh:mm:ss'
    )
)

Results:

image.png

Highlighted
Dual Super User
Dual Super User

Re: IF NULL: This should be easy!!

Hi @ericonline 

 

and what about

 

equals(items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time']
    ,null)

equals(items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time']
    ,'')

View solution in original post

Super User
Super User

Re: IF NULL: This should be easy!!

@RezaDorrani

NICE!

`equals(XYZ,null)` worked. 

Solution:

if(
    equals(
    items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time'],
    null),
    '1970-1-1 00:00:00',
    addseconds(
        '1970-1-1',
        Div(
            items(
                'For_each_childRecord')?
                ['attributes']?
                ['Observation_Date_Time'],
            1000
        ),
        'yyyy-MM-dd hh:mm:ss'
    )
)

Results for the null-value timestamp record:

image.png

Thank you both for the Flow expertise! 

Take care!

Super User
Super User

Re: IF NULL: This should be easy!!

Esoteric syntax! Would have loved to use: 

if(
    items(
        'For_each_childRecord')?
        ['attributes']?
        ['Observation_Date_Time']
    = null

Ah well, these are the types of things that make us valuable I guess. 

Thank you again Reza. I look forward to the TDGI event! 

Helpful resources

Announcements
Did you attend MBAS? Claim your badge

Attending MBAS? Claim your badge

Whether you’ve streamed the digital event live, or you're watching on-demand, claim your attendee badge to sport on your profile.

MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Users online (5,961)