Skip to main content

Notifications

Announcements

No record found.

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

  • Verified answer
    Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: Setting Primary Key

    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

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Setting Primary Key

    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.

  • chikhaleankush Profile Picture
    chikhaleankush 547 on at
    RE: Setting Primary Key

    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);


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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans