You can set the default status using the Defaults() function in your patch.
Patch(Accounts, Defaults(Accounts), {name: "Account Name"})
If you are trying to explicitly set the Status, you may need to consider:
- Setting both the statecode and statuscode fields at the same time
- There are not the same thing
- statecode is typically whether the record is Active (0) or Inactive (1)
- statuscode describes more of the 'Status Reason'
- The statecode and statuscode values are paired, and you'll need to know what are valid pairings
- Cannot set an 'active' statuscode with the 'Inactive' statecode, for example
- You can typically reference the Option Set / Status fields by referencing the field
- statecode: 'Status (Accounts)'.Inactive,
- statuscode: 'Status Reason (Accounts)'.Inactive
- It does appear as though Canvas apps, and Patches, cannot set a State/Status code for create (unlike other API calls)
- This may be due to a conflict with using Defaults()
- If you don't use Defaults(), you'll have to play whack-a-mole to determine all the fields it wants set
- You can, however, Patch the Account and immediately update the status
Create and then Update Status (using Account in CDS, as example)
UpdateContext(
{
locAccount: Patch(
Accounts,
Defaults(Accounts),
{name: "Inactive Account"}
)
}
);
Patch(
Accounts,
locAccount,
{
statecode: 'Status (Accounts)'.Inactive,
statuscode: 'Status Reason (Accounts)'.Inactive
}
)
MSFT Docs on Entity State/Status