web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Cloning Email with Power FX but having trouble setting Status Reason

(3) ShareShare
ReportReport
Posted on by 20
Hi all, I am trying to clone an received email.
 
I can get the record created with the Subject and body and by default it creates an outgoing email, so I'm trying to update the status but it's not working with what I have below. I can run a real time workflow on create to set the correct status' and that works but I feel it must be possible with Power FX or is it not possible?
 
Thanks in advance for any help.
 
Paul
 
Patch('Email Messages', Defaults('Email Messages'), {Subject: Self.Selected.Item.Subject & " - Clone -", Description: Self.Selected.Item.Description, Direction: Self.Selected.Item.Direction = 'Direction (Email Messages)'.Incomingstatecode : 'Activity Status (Email Messages)'.Completed, statuscode : 'Status Reason (Email Messages)'.Received});
 
 
EDIT: think the above might be an older way of referencing status', I've also tried it like this:
 
Patch('Email Messages', Defaults('Email Messages'), {Subject: Self.Selected.Item.Subject & " - Clone -", Description: Self.Selected.Item.Description, 'Activity Status': 'Activity Status (Email Messages)'.Completed, 'Status Reason': 'Status Reason (Email Messages)'.Received});
 
Categories:
I have the same question (0)
  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at
    Cloning Email with Power FX but having trouble setting Status Reason
    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.
  • Paul_D365_Developer Profile Picture
    20 on at
    Cloning Email with Power FX but having trouble setting Status Reason
    Thanks Amit but it doesn't seem to like that, it will accept 
    'Activity Status': 'Activity Status (Email Messages)'.'1'
    ​​​​​​​but that doesn't seem to work either?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 242

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 83 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 68 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans