It is possible to clone a received email and set its status correctly in Power Apps using Power FX, but the issue likely arises from how you're referencing the statecode (Activity Status) and statuscode (Status Reason). These fields often require specific numerical values instead of the display labels you're using.
Solution
Use the numerical values for statecode and statuscode instead of labels, as Power FX doesn't inherently resolve the labels in this context.
1. statecode (Activity Status):
Open: 0
Completed: 1
Canceled: 2
2. statuscode (Status Reason):
Draft: 1
Sent: 2
Received: 3
(Check the exact values in your environment for other reasons.)
Updated Power FX Code
Patch(
'Email Messages',
Defaults('Email Messages'),
{
Subject: Self.Selected.Item.Subject & " - Clone -",
Description: Self.Selected.Item.Description,
Direction: 'Direction (Email Messages)'.Incoming,
statecode: 1, // Completed
statuscode: 3 // Received
}
);
Notes:
1. Direction Field: Ensure 'Direction (Email Messages)'.Incoming resolves correctly to the corresponding value in your system. It may need to be replaced with its numeric equivalent (e.g., 0 for Incoming and 1 for Outgoing).
2. Testing: If the patch fails silently:
Use a Notify() function to confirm errors:
Notify("Error while patching email", NotificationType.Error);
Log outputs for debugging using Trace().
3. Workflow Alternative: While real-time workflows work well, they are not as flexible for dynamic scenarios. Using Power FX should be a cleaner approach if the numerical values resolve your issue.