cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BranoBeno
Level: Powered On

How to autogenerate Primary Name field in custom CDS Entity?

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

2 REPLIES 2
Kevin23
Level: Powered On

Re: How to autogenerate Primary Name field in custom CDS Entity?

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
Level: Powered On

Re: How to autogenerate Primary Name field in custom CDS Entity?

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

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Kudoed Authors (Last 30 Days)
Users online (3,766)