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)

Setting Primary Key

(0) ShareShare
ReportReport
Posted on by 760

Hi,

Does anyone know how to set the primary key in entities. I want to create an ID for each record in account, how can I set that field as the primary key?

Thank you in advance

*This post is locked for comments

I have the same question (0)
  • chikhaleankush Profile Picture
    547 on at

    Hey Rachelle,

    When the Entity is created, it does have a already built Primary Field. You do not externally need to create it. Also when you create a record for a Entity, Guid (Id) will be also automatically set. But if you want to set a lookup filed Then you need Guid, Name and Logical Name of the record.

    Below code might be of help!!!

    var lookup = new Array();
    lookup[0] = new Object();
    lookup[0].id = recorid;
    lookup[0].name = recordname;
    lookup[0].entityType = entityname;
    Xrm.Page.getAttribute("attributename").setValue(lookup);


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

    If you are creating a new record in the system, it will automatically set the Guid for you, however, if you are importing data, and you want to set the Guid yourself you can do it either from the SDK (using C#/.NET code), by supplying the Guid of the record, or if you are using SSIS with KingswaySoft for example, you can specify the Guid of the record that you will be creating there.

    Hope this helps.

  • Verified answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at

    Hi RachelleM,

    You can create a key field this will be alternate key but wont be primary key but acts as primary key. As we can have only one Primary key.

    Screenshot_5F00_31.png

    Please follow below links to generate GUID dynamically.

    https://weblogs.asp.net/haithamkhedre/generate-guid-from-any-string-using-c
    http://www.c-sharpcorner.com/UploadFile/prasoonk/guids-in-C-Sharp-and-net/

    Thanks
    Hemant

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