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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to select some fields as the primary key of an entity?

(0) ShareShare
ReportReport
Posted on by

when I build an entity, the system always auto-generate a primary key named --id,what shall I do to choose some fields as the primary key? 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    PranavShroti Profile Picture
    4,510 on at

    can you share bit more info on this.. because all records are assigned GUID by default in Dynamic CRM. If you need custom unique identifier (for each record) you can have auto generated numbers (alphanumeric also) associated with crm records using simple code.

    Hope this helps.

    Regards,

    Pranav

  • Suggested answer
    Nausher Sayeed Profile Picture
    522 on at

    For this you need to create your own custom unique identifier may be you can use plugin.

  • Community Member Profile Picture
    on at

    got it, thank you very much.

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    What is the purpose?

    You can also use the Keys feature in Dynamics 365. You can set an alternate way of creating new records by using a different set of alternate keys.

  • ashlega Profile Picture
    34,477 on at

    That's just the way Dynamics works - you can't define your own primary key

  • Suggested answer
    Somesh2207 Profile Picture
    1,563 on at

    Brite Global is correct. CRM will create its own GUID which is uses as unique identifier.

    But CRM also allows you to define your own Unique Key (which can be a single field or combination of fields) using the Alternate Key Mechanism.

    You can learn more on the alternate key in the below blog:

    http://www.cloudfronts.com/define-alternate-keys-for-an-entity/

  • Martin Donnelly Profile Picture
    1,030 on at

    What Alex meant to say is that Dynamics doesn't provide primary keys.  It provides guids as unique identifiers (pointers, if you will) and misnames them "primary key".  You will use the Keys feature to create actual primary keys.

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    You cannot change the Entity primaryid field to some other field. CRM using GUID as the Primary key for each record. You can change the name of the Primary field name - the text field not the ID field.

    If you definitely want to make some other field as Primary key, you could consider using Alternate Keys, this allows you to create up to 5 alternate keys.

    See the following

    "All Dynamics 365 for Customer Engagement apps records have unique identifiers defined as GUIDs. These are the primary key for each entity. When you need to integrate with an external data store, you might be able to add a column to the external database tables to contain a reference to the unique identifier in Customer Engagement apps. This allows you to have a local reference to link to the Customer Engagement apps record. However, sometimes you can’t modify the external database. With alternate keys you can now define an attribute in a Customer Engagement apps entity to correspond to a unique identifier (or unique combination of columns) used by the external data store. This alternate key can be used to uniquely identify a record in Customer Engagement apps in place of the primary key. You must be able to define which attributes represent a unique identity for your records. Once you identify the attributes that are unique to the entity, you can declare them as alternate keys through the customization user interface (UI) or in the code. This topic provides information about defining alternate keys in the data model."

     https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/define-alternate-keys-entity 

     

    Hope this helps

  • Martin Donnelly Profile Picture
    1,030 on at

    Again, what Kokulan meant to say is that Dynamics allows you to enter records without any primary key (hence, no PK constraint.)  It does set a GUID unique identifier and mistakenly labels it Primary Key -- we all know this to be the case having read E.F. Codd's seminal document on the relational model.

    If you wish to have an actual Key, primary or otherwise, you need to use the Keys feature to define it.  As one would expect, you must select a field or fields that in combination are unique to the entity records.  Key fields cannot be null, again, as prescribed by Codd.  The example account.accountnumber in all the documentation is a good one; none of you accounts should have been given the same account# as any other.  For a compound key think of apartments in your building.  Floor number is not specific enough and aptletter is not unique, but the combination will be -- e.g. 4F is unique (4th floor has many apartments; there is only one 'F' on each floor.)

    It is, however, a misnomer (Microsoft nonsense) that a GUID generated by the save button constitutes a primary key.

  • Alok Singh Profile Picture
    910 on at

    Hi,

    Name field can not be removed from the form.You can make this field optional and hide on the form.

    Being 'Name' as primary field, if the related  entity is used as a lookup on any other entity then due no value in name field ,user may find difficulty to select the correct record.

    You can write a workflow to set 'Name' field such as concatenation of 2 fields from the entity or you can change the display name in case of having any other field (field type of Single line of text).

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans