web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Conditional xpath form...
Power Automate
Unanswered

Conditional xpath formatDateTime

(0) ShareShare
ReportReport
Posted on by 678
formatDateTime(xpath(outputs('XMLRegulations'),concat('//Array[ID/text()="', item()['ID'],'"]/EndDate/text()'))?[0],'d','en-US')

This is being done in a select statement with mapping to create a variable.
That works if there's a value, but if there's no value I get an error, because it's trying to do a formatDateTime on null and barks at that.
So how would I add a conditional piece to it...concisely.
If null then this works..

xpath(outputs('XMLRegulations'),concat('//Array[ID/text()="', item()['ID'],'"]/EndDate/text()'))?[0]

Just not sure how to wrap this.

Categories:
I have the same question (0)
  • HamidBee Profile Picture
    932 Super User 2024 Season 1 on at

    You can use the "coalesce()" function to set a default value if the xpath expression returns null. The syntax would be:

    coalesce(formatDateTime(xpath(outputs('XMLRegulations'),concat('//Array[ID/text()="', item()['ID'],'"]/EndDate/text()'))?[0],'d','en-US'),'default value')


    This will format the date if it exists, otherwise it will return 'default value'.

    You could also use the "default()" function, which can accept default value with the same way.

    default(xpath(outputs('XMLRegulations'),concat('//Array[ID/text()="', item()['ID'],'"]/EndDate/text()'))?[0],'default value')

     

     

    If my reply helped you, please give a 👍, & if it solved your issue, please 👍& Accept it as the Solution to help other community members find it more.

  • sasrsc Profile Picture
    678 on at

    Thank you. I will try this and report back. One thing I did learn that addProperty by default won't add a null to the JSON but a "select" action will which is interesting. That helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard