cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
IrfanMukhtiar
Frequent Visitor

Retrieve Dynamic 365 Entities and show in a dropdown

Hi, I need help, 

Is there any method to develop a code component to be used in model driven apps that will collect all D365 entities and show in dropdown. 

 

Recently I have completed a code component that show current entity fields in dropdown. 

4 ACCEPTED SOLUTIONS

Accepted Solutions
DianaBirkelbach
Super User
Super User

Hi @IrfanMukhtiar , 

 

You can use the same way you've used for the fields. The only difference is how you retrieve the metadata for all entity names.

You could use the webAPI "EntityDefinitions" function.

export class RetrieveEntitiesRequest {
    getMetadata() {
        return {
            boundParameter: null,
            parameterTypes: {},
            operationType: 1, // This is a function. Use '0' for actions and '2' for CRUD
            operationName: "EntityDefinitions",
        };
    }
}

 and use it similar to this

const retrieveRequest = new RetrieveEntitiesRequest();  
webApi.execute(retrieveRequest).then(entityResponseParser)

 

Hope this helps!

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

the execute() function is there in PCF context. It isn't documented yet (so technically not supported) but is already pretty widely in use. So, to an extent it is "use at your own risk" but I have to believe that MSFT will inevitably make it a formal, documented part of the webapi object.

 

You just need to cast as any so you can use it in typescript, so something like this: 

(context.webAPI as any).execute(myRequest);

View solution in original post

DianaBirkelbach
Super User
Super User

Hi @IrfanMukhtiar , 

 

I totally agree with @cchannon .

I would add, that the "Xrm" object is not supported inside a PCF; this is specified in the docs: Power Apps component framework API reference - Power Apps | Microsoft Docs.

So "execute" seems the a safer way, even if not supported for now.

Hope this helps!

 

 

 

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

skoofy5
Super User
Super User

If I'm understanding you correctly then it's also a pretty straightforward xhr which I believe is supported.

            const queryUrl = "/api/data/v9.2/EntityDefinitions/?$select=LogicalName,DisplayCollectionName"

   let req = new XMLHttpRequest();
        req.open("GET", queryUrl, true);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200 || this.status >= 200 && this.status <= 206) {
                    const results = JSON.parse(this.response);

                }
            }
        };
        req.send();

 

View solution in original post

5 REPLIES 5
DianaBirkelbach
Super User
Super User

Hi @IrfanMukhtiar , 

 

You can use the same way you've used for the fields. The only difference is how you retrieve the metadata for all entity names.

You could use the webAPI "EntityDefinitions" function.

export class RetrieveEntitiesRequest {
    getMetadata() {
        return {
            boundParameter: null,
            parameterTypes: {},
            operationType: 1, // This is a function. Use '0' for actions and '2' for CRUD
            operationName: "EntityDefinitions",
        };
    }
}

 and use it similar to this

const retrieveRequest = new RetrieveEntitiesRequest();  
webApi.execute(retrieveRequest).then(entityResponseParser)

 

Hope this helps!

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Hi @DianaBirkelbach 

Thanks for responding, It helps me a lot to understand how to proceed further, but I have a query and would like to ask from you. 

 

I have followed PCF code component documentation and as per it we can use only 5 methods by using "webAPI", along with context but execute is not part of that mentioned methods. Snip is attached

 

Are you suggesting me to use XRM over context? 

I am looking forward for your kind reply. 

 

Thanks

Irfan Mukhtiar

the execute() function is there in PCF context. It isn't documented yet (so technically not supported) but is already pretty widely in use. So, to an extent it is "use at your own risk" but I have to believe that MSFT will inevitably make it a formal, documented part of the webapi object.

 

You just need to cast as any so you can use it in typescript, so something like this: 

(context.webAPI as any).execute(myRequest);
DianaBirkelbach
Super User
Super User

Hi @IrfanMukhtiar , 

 

I totally agree with @cchannon .

I would add, that the "Xrm" object is not supported inside a PCF; this is specified in the docs: Power Apps component framework API reference - Power Apps | Microsoft Docs.

So "execute" seems the a safer way, even if not supported for now.

Hope this helps!

 

 

 

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."
skoofy5
Super User
Super User

If I'm understanding you correctly then it's also a pretty straightforward xhr which I believe is supported.

            const queryUrl = "/api/data/v9.2/EntityDefinitions/?$select=LogicalName,DisplayCollectionName"

   let req = new XMLHttpRequest();
        req.open("GET", queryUrl, true);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200 || this.status >= 200 && this.status <= 206) {
                    const results = JSON.parse(this.response);

                }
            }
        };
        req.send();

 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Users online (2,353)