I have seen several topics on this question but I can't seem to get any of the solutions to work. I have a Date field that's not required in a SharePoint List. If a date gets entered I want the date to be formatted; if a date is not entered I just want it to output nothing.
I keep getting this error: function 'formatDateTime' expects its first parameter to be of type string. The provided value is of type 'Null'.
It seems like the False outcome in the If experssion I made still gets evaluated and throws an error if the condition is true. The
The Date Column is called "Test Date" in the example above.
Thanks in Advance
your syntax is correct, but the reason this fails is (I think) because formatDateTime(triggerBody()?['Test_x0020_Date'],'D') is probably computed (somewhere in a stack) but its result is not applied if 'Test Date' is null. and this crashes because formateDateTime cannot work if a date is null.
The proof is if your write:
if(equals(triggerBody()?['Test_x0020_Date'],null),'X','Z') this should work.
I know it is weird..
You can store the value in a variables or just use a normal condition action.
Could you please share a screenshot of your flow's configuration?
The error message told that the formatDateTime function expects its first parameter to be a string, but you provide a Null value.
I have made a test on my side and the issue is confirmed on my side. My flow's configuration as below:
Inputs set to following formula:
The error shows up as below:
I think the issue is related to If() function, the True value and False value within If() expression would be calculated at the same time with If Conditional judgment.
In addition, you could consider take a try to achieve your needs with following workaround:
The flow works successfully as below:
When the Test Date column is not entered:
When the Test Date column is entered:
thank you for your answer; the IF behavior has been escalated to the LogicApps team; lazy evaluation will be implemented for future runs because it is more intuitive ( and more efficient) for most users
The conditional statements may be useful if we just had to check for one null value but I have to check for a number of them. I will instead make the fields required and not proceed unless they are all not null instead. Thanks for the solution.
@sergeluca, Lazy evalution will be much appreciated when it comes out.
I am having issue, i am stroing the date values into a varible but is it is not having date "Questions Due Date", i am getting error 400 while saving the field is of type Date only in CRM.
Where as same date as JSON is accepting/showing null and if i am trying to pass null / '' which is not acceptable.
Hello @v-xida-msft ,
I have this same issue, I have 4 leave types (TimeOff, Annual Leave, Casual, Sick) which user selects and enters the data according to the selected leave type in PowerApps,
I insert the data into SP list by using patch function in which if the user selects LeaveType as "Time Off" then only TimeOff related things are inserted in SP List.
Now, I am running a flow whenever an item is created an email is sent to the manager and then he/she accepts or rejects.
I have used all the fields in the Start and Wait For Approval Step to show the details whichever leave type is selected.
The First FormatDateTime expression is for Time Off Date, the last two are Start Date and End Date used in Leave Types (Annual, Casual and Sick).
So, when the user posts TimeOff record, the start and end date are null in that record, so my flow shows an error.
and this happens with Annual, Casual and Sick, when the user create this, then TimeOff Date goes null.
So, my Flow Run Fails..
Another option (and much easier) is to simply create a calculated column in the SharePoint list that leaves the field blank if null or formats the date if not null.
This field does not have to be added to a view - and can be added as dynamic content in the flow.
Learn how to create your own user groups today!
Check out the new Power Platform Community Connections gallery!
Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.