cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User II
Super User II

Retrieve GlobalOptionSetDefinitions in JavaScript

Has anyone successfully been able to query GlobalOptionSetDefinitions in JavaScript or TypeScript using the Xrm client API? Tried the regular Xrm.WebApi.retrieveRecord, Xrm.WebApi.retrieveMultiple and also with Xrm.WebApi.online.execute but no success. I know we can use XMLHttpRequest but was hoping we would be able to achieve with the out-of-the-box libraries...

 

According to the OData metadata, GlobalOptionSetDefinitions an entity and is queryable. For example:

 

https://env.crmN.dynamics.com/api/data/v9.1/GlobalOptionSetDefinitions(Name='fieldname')?$select=Name

{
  "@odata.context": "https://env.crmN.dynamics.com/api/data/v9.0/$metadata#GlobalOptionSetDefinitions/Microsoft.Dynamics.CRM.OptionSetMetadata(Name)/$entity",
  "@odata.type": "#Microsoft.Dynamics.CRM.OptionSetMetadata",
  "Name": "fieldname",
  "MetadataId": "a267ef1d-3e96-ea11-a812-000d3a797005"
}

 

Here's the error with Xrm.WebApi.online.execute. There used to be a retrieveMultiple operationName option but seems gone now. 

 

 

 

var Sdk = window.Sdk || {};
Sdk.RetrieveRequest = function (entityReference) {
    this.entityReference = entityReference;
};
Sdk.RetrieveRequest.prototype.getMetadata = function () {
    return {
        boundParameter: null,
        parameterTypes: {},
        operationType: 2,
        operationName: "Retrieve",
    };
};
var entityReference = {
    entityType: "GlobalOptionSetDefinitions",
    id: "a267ef1d-3e96-ea11-a812-000d3a797005"
};
var retrieveRequest = new Sdk.RetrieveRequest(entityReference);

return Xrm.WebApi.online.execute(retrieveRequest).then(
    function (result) {}, function (error) {}
);

error code 2147746581 
An error has occurred. Try this action again. If the problem continues, check the Microsoft Dynamics 365 Community for solutions or contact your organization's Microsoft Dynamics 365 Administrator. Finally, you can contact Microsoft Support. 

 

Here are the errors with retrieveRecord and retrieveMultipleRecords (same with plural or singular entity name)

 

Xrm.WebApi.retrieveRecord("GlobalOptionSetDefinitions", "a267ef1d-3e96-ea11-a812-000d3a797005")
Xrm.WebApi.retrieveMultipleRecords("GlobalOptionSetDefinitions", "?$select=*&$filter=Name eq 'xyz'")

errorCode: 2147868684
message: "The entity "GlobalOptionSetDefinitions" cannot be found. Specify a valid query, and try again."
code: 2147868684

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Retrieve GlobalOptionSetDefinitions in JavaScript

At the risk of splitting hairs! 😀...


These metadata request are a bit 'special'- they are actually entity sets (although they do at first sight look like functions) and accept alternate keys as their key indexer.

So it's actually a complete fluke that using Xrm.WebApi.execute works because it's not a function - but the url to call it *looks* like a function with the alternative key being a parameter!

 

E.g.

GET /api/data/v9.0/GlobalOptionSetDefinitions(Name='myglobaloptionset')

Name - is actually an alternative key - not a function parameter.

I would be careful about using Xrm.WebApi.execute to query this 'special' entityset as a function because it might not always work in the future. 

 

The reason why we can't query GlobalOptionSetDefinitions (or EntityDefinitions) using the the Xrm.WebApi.* api is because no CDS entity metadata exists for these special entity sets - they are only described in the ODATA metadata as :

 

 

<EntitySet Name="GlobalOptionSetDefinitions" EntityType="Microsoft.Dynamics.CRM.OptionSetMetadataBase" />

 

 

So you will always get the error "The entity "GlobalOptionSetDefinition" cannot be found. Specify a valid query, and try again."

To be technically correct, taking into account this limitation, a WebApi request should be sent manually rather than using the Xrm.WebApi.*

Something like:

fetch("/api/data/v9.0/GlobalOptionSetDefinitions(Name='myglobaloptionset')").then(a=>a.json().then((b)=>console.log(b)))

...however, @DianaBirkelbach's approach does work at the moment! 😀



View solution in original post

6 REPLIES 6
Highlighted
Community Support
Community Support

Re: Retrieve GlobalOptionSetDefinitions in JavaScript

Hi @EricRegnier ,

Do you want to retrieve the GlobalOptionSetDefinitions using Xrm Client API rather than Web API?

 

Based on the issue that you mentioned, I have made a test on my side, and same issue just as you mentioned show up. The screenshot as below:

9.JPG

 

I afraid that the GlobalOptionSetDefinitions Entity is not supported in Xrm Client API. As an only possible solution, I think the Web API could achieve your needs.

 

If you would like this feature to be added in PowerApps, please submit an idea to PowerApps Ideas Forum:

https://powerusers.microsoft.com/t5/Power-Apps-Ideas/idb-p/PowerAppsIdeas

 

In addition, I could not find any resource mentioned above retrieving GlobalOptionSetDefinitions Entity records using Xrm Client API, except the Web API.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Super User II
Super User II

Re: Retrieve GlobalOptionSetDefinitions in JavaScript

Hi @v-xida-msft, yep with the Xrm.WebApi client Library

Highlighted
Community Support
Community Support

Re: Retrieve GlobalOptionSetDefinitions in JavaScript

Hi @EricRegnier ,

I have made a test on my side, and reproduce your issue, I afraid that the GlobalOptionSetDefinitions Entity is not supported in Xrm Client API yet.

Note: The Xrm.WebApi.retrieveMultipleRecords() formula that you mentioned is in right direction.

 

You could consider submit an assisted support ticket through the following link for further help:

https://powerapps.microsoft.com/en-us/support/pro

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Super User
Super User

Re: Retrieve GlobalOptionSetDefinitions in JavaScript

Hi @EricRegnier , 

This request worked for me:

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

Xrm.WebApi.execute(new RetrieveEntitiesRequest()).then(console.log, console.error)

Similar with your try, but GlobalOptionSetDefinitions is not an entity, but a function.

DianaBirkelbach_0-1594815485277.png

 

Hope this helps! 

 

Kind regards,

Diana

Highlighted
Super User
Super User

Re: Retrieve GlobalOptionSetDefinitions in JavaScript

At the risk of splitting hairs! 😀...


These metadata request are a bit 'special'- they are actually entity sets (although they do at first sight look like functions) and accept alternate keys as their key indexer.

So it's actually a complete fluke that using Xrm.WebApi.execute works because it's not a function - but the url to call it *looks* like a function with the alternative key being a parameter!

 

E.g.

GET /api/data/v9.0/GlobalOptionSetDefinitions(Name='myglobaloptionset')

Name - is actually an alternative key - not a function parameter.

I would be careful about using Xrm.WebApi.execute to query this 'special' entityset as a function because it might not always work in the future. 

 

The reason why we can't query GlobalOptionSetDefinitions (or EntityDefinitions) using the the Xrm.WebApi.* api is because no CDS entity metadata exists for these special entity sets - they are only described in the ODATA metadata as :

 

 

<EntitySet Name="GlobalOptionSetDefinitions" EntityType="Microsoft.Dynamics.CRM.OptionSetMetadataBase" />

 

 

So you will always get the error "The entity "GlobalOptionSetDefinition" cannot be found. Specify a valid query, and try again."

To be technically correct, taking into account this limitation, a WebApi request should be sent manually rather than using the Xrm.WebApi.*

Something like:

fetch("/api/data/v9.0/GlobalOptionSetDefinitions(Name='myglobaloptionset')").then(a=>a.json().then((b)=>console.log(b)))

...however, @DianaBirkelbach's approach does work at the moment! 😀



View solution in original post

Highlighted
Super User II
Super User II

Re: Retrieve GlobalOptionSetDefinitions in JavaScript

Thanks @ScottDurow and @DianaBirkelbach. I ended up using fetch like Scott suggested, it's a lot cleaner than XMLHttpRequest. I'm hesitant to use the function call since GlobalOptionSetDefinitions seems unsupported and not documented in the list of functions: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/functions?view=dynamics-ce-...

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Users online (6,543)