May 13, 2019

How to add 'Actions' on Odata entities


Hi Folks,


[Updated on Jan 27, 2020
I got one feedback about Odata action on entity extension are not supported. It worked for me for one odd case, I yet to test myself if its not working now. I would request all readers to take necessary caution while trying below code. Thanks to Ashish for sharing his feedback.]


In this post, I'll show how to add a new action to D365FO Odata entities which you may want to access in Logic apps or Microsoft Flow. There could be two possible scenarios, either you have custom data entity where you can directly add a method or you have standard data entity for that you need to create extension class.  

First, let's see how to add on the custom entity (yes cause, it's straight forward 😉 ), 

Add your method on data entity and add below attribute
 [SysODataActionAttribute("<MethodName>", false)]
public static void <methodName>(<parameters(optional)>)
{
}

Save, Synch and Build your changes. This method should be available now on OData action in the Logic app or Flow. 

Now the other part, how to add the same in Data entity extension. Create a new class and add below attribute.

[ExtensionOf(tableStr(<data entity name>))]
final class <data entity name>_Extension
{
         [SysODataActionAttribute("<MethodName>", false)]
         public static void <methodName>(<parameters(optional)>)
        {
         }
}

Pl make sure you use '_Extension' keyword for above class, it's mandatory.

That's all for today. Try it and share your feedback. 

[Updated May 18, 2020]

 If you want to return any value use this syntax

 [SysODataActionAttribute("<MethodName>", false), SysODataCollectionAttribute("return", Types::Record, "CarColor")]

         public static void <methodName>(<parameters(optional)>)

        {

         }


Check below link for more details on Odata


Related topics:

-Harry Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta


14 comments:

  1. Hi Deepak

    I'm wondering on which platforms you have tried/developed this code.

    We're on 10.0.1, PU24, but using this approach we can't get the expected result. The new action does not appear in metadata.

    BR, Atis

    ReplyDelete
  2. Hey Atis,

    I have tried this code with V8.0 and this should work with v10.x as well. Can you share some screenshot or reference where its not working.

    Thanks

    ReplyDelete
  3. Hello Deepak,

    We tried the same approach of adding an action using entity extension class and it doesn't appear in LogicApp. We have created action on ExpenseJournalHeaderEntity. It has no standard action OOB. Do we need to do anything additional after adding action? We tried in 10.0 PU26

    ReplyDelete
  4. Hi Deepak,

    Just small clarification OData action as an Extension on Standard Data Entities is not supported even as per MS Yammer group. My humble advice is please remove that section and mention the same.

    Ashish

    ReplyDelete
  5. I tried through extension and is not working as well. Example code below. It's not complete but I can't even call this from postman.

    [ExtensionOf(tableStr(InventInventoryAdjustmentJournalHeaderEntity))]
    public final class AVISGIInventInventoryAdjustmentJournalHeaderEntity_Extension
    {
    [SysODataActionAttribute("printLabelsForJournal", false)]
    public static void printLabelsForJournal(JournalId _journalId)
    {
    JournalId journalnumber = "Get the current record";
    }

    }

    ReplyDelete
  6. Even i am facing the same issue. It isn't listing down in the Execute actin as well.
    Full DB Sync, Build are also done.

    ReplyDelete
  7. Even i am facing the same issue. It isn't listing down in the Execute actin as well.
    Full DB Sync, Build are also done.

    ReplyDelete
    Replies
    1. Hey Mithila, Can you pl share your code, want to check once.

      Delete
  8. Hi I have a question on how to call Entity Action with parameter in C# program.

    ReplyDelete
  9. Hi I am wondering how to call Entity action with parameter in C#.

    ReplyDelete
  10. OData actions added via extensions are currently not supported by MS.
    Reference https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/odata

    ReplyDelete
    Replies
    1. Hi Deepak, Thanks for the feedback. I have mention this update on the post.

      Delete

Thanks