cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kudo Kingpin
Kudo Kingpin

What is Key in CDS?

Serious, what is Key in CDS? please share an example not an article

4 REPLIES 4
Power Apps
Power Apps

 

Hi @Yahya - by default CDS entities have a GUID as their only unique field - but in another system you may use something like a Customer ID, or Order Number to uniquely identify a particular record. Defining a key allows you to make sure your field is also unique, and CDS won't allow duplicates of data to be entered within it. This can be especially helpful if you're integrating your data with an external system that uses that ID or number to identify a record (and not the CDS GUID). It also improves the search and filtering on the particular field, as we have indexes in place.

 

Keys can be based on a single field (Order ID) or a combination of fields (example : Financial year and Order ID). If you set a key on a field and try to enter duplicate data, the record will fail to save.

 

Does this help?

Thanks,
Clay.

Hi @CWesener, Thanks for the response. This reminds me with the property "Unique" in Access Web Apps database.

 

2 things I would like to mention: -

 

1. Creating a key via the PowerApps studio (online) will not prevent duplicating a record. This occurred in my tenant at least and I am willing to organize an online session so your team checks by themselves.

 

I trued the Solution explorer, checked my index which I created from PowerApps studio to find that there is one more step to be done on the key, to activate/resume. it failed anyhow because of existing duplicates I think.

 

I deleted, recreated, activated and it has worked perfectly then.

 

There is therefore somethng missing in creating a key from the PowerApps studio that need to be fixed.

 

2. Not all fields can be set as a Key for instance a Look up field. Now think of this scenario, I have 2 custom entities on the top of my database model, one is COUNTRY and the other is CITY. While I have entered all countries we work with, like 80 or so, cities are to be added by the users. I could create a key in CITY that is the City Name but for this is not correct in real life, as for instance, I have 2 cities called Tripoli, one is in Libya and the other is in Lebanon. So the right thing is to create a key from the concatenation of City Name and Country in the CITY entity, something not available because also calculated fields are not possible available to key feature.

 

The same goes for a CUSTOMER and PROJECT REFERENCE, so none of my customers would have 2 different projects under the same PROJECT REFERENCE.

 

what would be your thoughts handling this?

 

 

 

Hi @Yahya,

 

Regarding the first issue - can take a few minutes for the key to be created, so if you immediately go and enter data, it wont be unique, and then the key will fail. We are looking at improving this experience in the portal.

 

For the second item, this would be a new feature for us to support more data types in keys - can you please raise an idea on the ideas forum?

 

Thanks,

Clay.

Thanks,
Clay.

Regarding the unique key issue. It didn't work for me. I've been waiting for more than 30 minutes and I'm still able to add duplicated récords, so, maybe there is a kind of bug or something, or is it possible that I need to wait for a longer period? 

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Check out the Power Apps Community Call for January 2021

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Users online (11,695)