Dynamics 365: Solving the Action Invalid Argument error with Flow

Nick Chin, 23 October 2019

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.

To recreate this as a Flow:

  1. 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.

  1. Make sure the Environment is Default and the Entity Name is correct.

  1. 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.

  1. 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”

  1. Add “Apply to each” and select “value” from “List records”

  1. Add the action “Update a Record”

  1. Set the fields
    Environment: (Current)
    Entity Name: Accounts
    Record Identifier: select the original “Account” from the “When a record is selected”.

  1. 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.

  1. The Flow is now complete, make sure the Flow is turned on then its ready to run.

  1. Browse in CRM to the Account and open the Flow menu and select the Flow that was created under Run.

  1. A pop up will appear click run

  1. After a enough time has passed for the Flow, you can refresh the account.
    Then the Highest Priority Case lookup will be updates.

Here I have successfully replaced an action, which can be manually run, and it won’t cause an error if there are no child cases returned.