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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to autogenerate Pr...
Power Apps
Unanswered

How to autogenerate Primary Name field in custom CDS Entity?

(0) ShareShare
ReportReport
Posted on by 3

Primary Name field is by default "Required". How to fill this field by GUID or random number on save?

I have the same question (0)
  • Kevin23 Profile Picture
    47 on at

    You could do a few things. 

    • Change the requirement level of the field to Business Recommended or Optional (you'll need to do this for all of the below options).
    • Use the D365 autonumber service to create an autonumber and populate it in the field. You can easily acheive this with XRMToolbox and a plugin.
    • Use javascript to either generate a GUID or copy the recordid field to the name field
    • Use workflow to copy values from other fields to the name field (this would be the easist and generally recommended thing to do as the primary name field is used to display records in lists in D365/model driven apps

    Kev

     

  • BranoBeno Profile Picture
    3 on at

    Thanks for tips. For now most comfortable was to use JavaScript in attributeOnChange on form when some required field is changed:

     

     var Sdk = window.Sdk || {};
     (function () {
     this.attributeOnChange = function (executionContext) {
     var formContext = executionContext.getFormContext();
     var primaryname = formContext.getAttribute("cr309_primaryname").getValue();
     if(primaryname==null){
     var chars = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];
     var str = "";
     for(var i=0;i<36;i++) {
     var str = str + ((i == 8 || i == 13 || i == 18 || i == 23) ? "-" : chars[Math.floor(Math.random()*chars.length)]);
     }; 
     formContext.getAttribute("cr309_primaryname").setValue(str);
     }
     }
     }).call(Sdk);

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 802 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 332 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 273

Last 30 days Overall leaderboard