web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Retrieve GlobalOptionS...
Power Apps
Unanswered

Retrieve GlobalOptionSetDefinitions in JavaScript

(0) ShareShare
ReportReport
Posted on by 8,720 Most Valuable Professional

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!

I have the same question (0)
  • v-xida-msft Profile Picture
    on at

    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,

  • EricRegnier Profile Picture
    8,720 Most Valuable Professional on at

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

  • v-xida-msft Profile Picture
    on at

    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,

  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    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

  • Verified answer
    ScottDurow Profile Picture
    1,039 on at

    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! 😀



  • EricRegnier Profile Picture
    8,720 Most Valuable Professional on at

    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-odata-9

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard