Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Clone field of entity while creating it

Posted on by 282

Dea All,

I want to add a custom logic while creating fields in an entity in Dynamics 365.

The requirement is : when creating new field in an entity A => create clone of the field in entity B.

To do so, i can use the message : CreateAttributeRequest.

Now i need to catch the event of creation of a field.

In Plugin Registration Tool, i found the message: CreateAttibute, so i tried to register a step in my plugin but still i cannot fill a valid Primary Entity Name. I get the error below :

  • Error message : Invalid PrimaryEntity Name specified. Please re-enter the PrimaryEntity name (see attached file)
  • CreateAttribute-_2D00_-invalid-entiyname.PNG

So i tried to leave it clear and still i got an error while registring the step.

  • Error message : Registration of a new processing step for CreateAttribute and Any Entity is not premitted.  (see attached file)
  • CreateAttribute-_2D00_-Empty-entityName.PNG

Can someone suggest me something please ?

  • Verified answer
    RE: Clone field of entity while creating it

    Hi Saad,

     

    Yes, it is possible to create Attributes/Fields using a plugin, but you need to adjust the Message and Event Pipeline Stage of Execution of your Plugin, taking in consideration the information below:

     

    • Message

     

    Unfortunately it is not possible to use this message CreateAttribute as a trigger for the plugin. There are many Messages that, although you can see into the PRT (Plugin Registration Tool) drop list, it is not really available. PRT runs a query against a table in CRM that list all the messages but it doesn’t mean that all of them are available to register.

     

    There is an easy way that you can confirm if a message is functional, which is trying to type only the first word of the Entity, PRT must auto complete the Entity name if such Entity is a valid PrimaryEntity for that message (see print screen below as example). If PRT is not auto completing the name of the Entity, it means that such Entity is not valid for the given message. If there is no PrimaryEntity valid for a given message it means that the message is actually not available for register a plugin. That is the case for message CreateAttribute.

    pastedimage1586770514088v1.png

    If you want to confirm all the valid Messages to be registered in a Plugin, you can follow this documentation: https://powerapps.microsoft.com/en-us/blog/find-messages-and-entities-eligible-for-plug-ins-using-the-common-data-service/ or just run this web api below in your browser, and you will check that CreateAttribute will not be listed there:

     

    https://<YourOrg>/api/data/v9.1/sdkmessages?$select=name&$filter=isprivate eq false and (name ne 'SetStateDynamicEntity' and name ne 'RemoveRelated' and name ne 'SetRelated' and name ne 'Execute') and sdkmessageid_sdkmessagefilter/any(s:s/iscustomprocessingstepallowed eq true and s/isvisible eq true)&$expand=sdkmessageid_sdkmessagefilter($select=primaryobjecttypecode;$filter=iscustomprocessingstepallowed eq true and isvisible eq true)&$orderby=name

     

    More information available here: https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/event-framework

     

    Said that, you must use a different Message to trigger your plugin.

    • Event Pipeline Stage of Execution

     

    Create an Attribute from a Plugin is possible, but you must take in consideration some specifics:

     

    For Pre-Operation and Post Operation this behavior won't be possible. You would get an Exception like this: "You cannot start a transaction with a different isolation level than is already set on the current transaction".

    Therefore you must register the plugin in Pre-Validation or Async Post-Operation, for the last one, the attribute will not be available until you run Entity Publish or Publish all

     

    Sample code and more details are available in this thread:  https://community.dynamics.com/365/sales/f/dynamics-365-for-sales-forum/382428/createattributerequest---field-is-created-but-cannot-be-found

  • rthompson Profile Picture
    rthompson 1,530 on at
    RE: Clone field of entity while creating it

    Hi Saad,

    This is not possible.  You can not automatically create fields in an entity.  You have to use the "Customize the system" to create a field in an entity.

  • saad nadir Profile Picture
    saad nadir 282 on at
    RE: Clone field of entity while creating it

    No its not regarding the data, its regarding the definition of the field.

    I want to automate the creation of fields in entities :

    => From the solution, if i create a field in entity A, i want to create automatically an image of the field in the entity B.

    For this i need to know which message to use and what primary entity to use. is there any supported way designed by Microsoft ?

  • Suggested answer
    rthompson Profile Picture
    rthompson 1,530 on at
    RE: Clone field of entity while creating it

    Hi,

    I am a little confuse on what you are asking.  Are you saying that you want to take data from Entity A and copy that data to Entity B.

    If this is what you are trying to do, then use the plugin postoperation on Entity A and Update Entity B from Entity A.

    I am accusing your question.

  • Suggested answer
    RE: Clone field of entity while creating it

    Hi Saad,

    Accordingly with docs.microsoft.com/.../supported-messages-entities-plugin

    there is no such message with name "CreateAttribute" for plugins for custom entities. Same for account

    docs.microsoft.com/.../account

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans