Have you ever had the “Invalid Argument” error from an Action before?
This can happen when you are retrieving a record with code and it returns a null. If an Action has an EntityReference output, then it must always return data.
So, if you encounter this problem, what should you do?
If the logic is complicated, I’d recommend you replace the action by using a Custom Workflow or Plugin. Alternatively, if the Action’s logic is simple then you can create a Flow, which means you wouldn’t need to write a single line of code.
As you may already know, Microsoft is promoting “Flow”.
Out of the box “Flow” has a wider range of functionality than Workflows. To match this, Workflows would need to extend their functionality with Custom Workflows.
Let’s create a Flow from scratch using my example scenario:
There is an existing action that will update the Account with its highest Priority Case. The action was executed manually and throws an “Invalid Argument” error if the Account has no child Cases.
Create a Manual Flow using the CDS Trigger “When a record is selected”.
You can view instruction on how to quickly create a manual Flow here.
Make sure the Environment is Default and the Entity Name is correct.
Then add a Condition to check the “Status Value” is equal to 0. Note that it is using “0” as an Expression. This to check the Account is active.
In the Yes section of the Condition add the Common Data Service (CDS) “List records”.
Environment: Select “(Current)”
Entity Name: Select “Cases”
Filter Query: To find the cases for the Account you need to use “_customerid_value” to get the guid then select Account from the Dynamics Content.
“_customerid_value eq Account”
Order By: “prioritycode, createdon”
Orders by prioritycode then created on. The highest priority will be 1.
Top Count: we only want the case that is the highest priority so set this to “1”
Add “Apply to each” and select “value” from “List records”
Add the action “Update a Record”
Set the fields
Entity Name: Accounts
Record Identifier: select the original “Account” from the “When a record is selected”.
Open the “advanced options” and select the “Highest Priority Case” field.
Search the Dynamics Content for “Case” under “List records”. The Case is the Unique Identifier, which will set the “Highest Priority Case” lookup.
The Flow is now complete, make sure the Flow is turned on then its ready to run.