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
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 136 members 4,535 guests
Please welcome our newest community members: