In the form, this field is optional, so sometimes the user leaves it blank - Its okay but in the backend is the field is mandatory, If yes make the field as not required one!
However with the problem, will try with Simple solution, try create a condition control branch
empty(outputs('Get_response_details')?['body/FieldID'])
Yes - > Create item action without the date field at all
No -> Create item action with proper date field format.
item/Contractstartdate: formatDateTime(
outputs('Get_response_details')?['body/FieldID'],
'yyyy-MM-dd'
)
Or other way we will optimize ur current code.
if(empty(outputs('Get_response_details')?['body/FieldID']), null, formatDateTime(outputs('Get_response_details')?['body/FieldID'], 'yyyy-MM-dd'))
To
coalesce(
if(
empty(outputs('Get_response_details')?['body/FieldID']),
null,
formatDateTime(outputs('Get_response_details')?['body/FieldID'], 'yyyy-MM-dd')
),
null
)
If this also doesn't work pass this to compose action & compose action output to the create item sharepoint action.
Revert me if you have any queries.
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item