A few weeks ago I looked at calling flows from model driven apps. And for a while my flow worked as expected and then suddenly it broke with an “Expected String but got Null” message
Calling a flow from a Model driven app
Table of Contents
When you call a flow from a model driven app you would normally expect to see a dialog with a Run flow button.
In the past this worked as expected but recently I got the Something went wrong. please refresh the page or try again after some time.
Well, you can wait for a while, but this isn’t going to fix itself.
As you scroll down the dialog you will find the details of the error. in my case i got :
Error: The input body for the trigger ‘manual’ of type Request did not match its schema definition. Error details: ‘Invalid type. Expected String but got Null , invalid type Expected String but got Null
That still doesn’t mean very much!
Something is wrong with he trigger and something is wrong with the data in the trigger.
ok, what should we do to fix this issue.
Expected String but got Null workaround
Hopefully Microsoft will fix the real issue soon, but in the meanwhile I fot a good workaround. Hopefully this will help some other people. As it can be very painful when you run into this issue. It will simply be impossible to run the flows from your Model driven app without getting the Expected String but got Null.
My flow start with a When a record is selected trigger.
Then in the rest of the flow I was using information returned by this trigger. These references to the trigger are the causes of the problem.
So we have to avoid those. There is however one field that we can reference and that is the opportunity id. Any other properties that we reference might mean that the schema ( the shape of the data that is sent between the Model-driven app and the flow) might change. You adding another reference to a different field may change this schema.
To avoid this, we can use a get a record action.
In the get a record action we reference the opportunity. and now in any of the following steps we can only use dynamics data from this Get a record action rather than from the trigger.
Both the trigger and the get a record action will return exactly the same data anyway. So other than one maybe unnecessary extra call to the database, there isn’t too much of a disadvantage of using this method.
Hi Pieter,
I encountered the same issue today. But strangely my flow was somethimes working and sometimes giving the error you mentioned.
When inspecting the trigger with ‘peek code’ it showed two field that it is using further down in the flow. So it looks like a automatic ‘rollup’ of all fields that are used.
Unfortunatiely the fields are flagged as ‘required’
So that is why my flow sometimes works. As long as all field are filled, it works. I like it this way, because I need both fields.
If one of them is optional, your workaround is great.
Most likely the sometimes working is down to the actual values in the data. When fields are not supplied they will be set to null and therefor without a datatype
Would be great if Microsoft came up with a holistic solution to null fields – real pain to always check for null! Often use many ‘not required’ fields and checking them every time for null to avoid unsuccessful flows down the line is a constant issue 😦 that folk seem to run into
Yes, there are plenty of things that could be made easier.
It worked like a charm, thanks!
This was very helpful, thank you! There is one thing I need that can’t be obtained from the ‘get a row by id’ action, which is the user email for the initiator of the flow. Do you have any suggestion for that?
Is this for a manually triggered flow?
The following expression should work:
triggerOutputs()[‘headers’][‘x-ms-user-name-encoded’]
Thank you so much for your prompt reply!
triggerOutputs()[‘headers’][‘x-ms-user-name-encoded’] is what I had in the To: field for Send an email (V2), and this resulted in the following error:
The ‘inputs.parameters’ of workflow operation ‘Send_an_email_(V2)_Original_Approved_Start_Date_Needed’ of type ‘OpenApiConnection’ is not valid. Error details: Input parameter ’emailMessage/To’ is required to be of type ‘String/email’. The runtime value ‘”bmN4d2JAZHMuaXJzbmV0Lmdvdg==”‘ to be converted doesn’t have the expected format ‘string/email’.
triggerOutputs()?[‘headers’][‘x-ms-user-name-encoded’] is what picking the dynamic content called ‘User Email’ gives you, but based on where I see an actual email address in the outputs of the trigger, it looks like what’s needed is
triggerOutputs()?[‘headers’][‘x-ms-user-email’]
In the one test run done with this value, it succeeded. Hope this helps anyone else needing to use that email!
But what is the solution when I have an integer input at when a record is selected step and the same error occurs to me?
Knowing that this flow works well with the system admin user, but an error occurs for the rest of the users.
The same workaround should work.