we have a requirement where we have to retrieve an Entity's Metadata. Exact requirement: Im reading a field value on a form which ia having "entity schema name". With that I need to get that Entity's primary key schema name. Is it possible? If so please help me. Eg: in that field if I enter "lead" , that web api should fetch me "leadid" and store it in another field. 2. If I enter "incident" , that web api should get me "incidentid"
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Yeah, I do agree that there is no need to retrieve if it's primary key schema name as for each entity it's entity schema name + id (Lead + id = leadid). But, we felt it's not a good practice. We achieved this with the following code... It's perfectly working fine. When we provide correct Entity Schema Name, it will automatically populate that Primary Id Attribute into another field. new_primarykey - where I am populating the Primary Key Schema Name on entering Entity Schema Name in new_entityschemaname fieldon the form.
enter image description here
First of all, thanks for Sharing. I am currently working on a global button on form level which JavaScript that should get the primary key of the specific entity. I also started with entityName + "id", but this will fail on activity entities like email etc. So I started to implement the above.
When you get the entity's logical name via a form in javascript:
You get for example "opportunity" and when you add this as the var for
entityName
to thegetPrimaryKey
this will fail because theSchemaName
of the entity is Opportunity and not opportunity. Also for Account etc.So my advice is when you work with
.getEntityName()
to useLogicalName
instead ofSchemaName
which results in the following URL:You don't need do retrieve entity metadata for that, primary key is always "entity schema name" + "id", there are no exceptions from that rule. If you still want to retrieve metadata, you should be able to do it by calling:
That would return all attributes for entity "account", primary key is the one without any "@odata.type" attribute