Notifications
Announcements
Hi,
I have created an Environment Variable in my Power App Solution and I want to access the value of the variable using the Web API in a Web Resource with JavaScript.
Could this done using XRM in Javascript ?
Thanks
- Rory
Hello Rory,
Generally speaking "Environment Variable" is 2 entities in CDS that are available through api.
You should query entities environmentvariabledefinition (to apply the filter by variable name) and environmentvariablevalue to get the value. Generally speaking following FetchXml should bring you what you need:
<fetch> <entity name="environmentvariabledefinition" > <filter> <condition attribute="schemaname" operator="eq" value="test" /> </filter> <link-entity name="environmentvariablevalue" from="environmentvariabledefinitionid" to="environmentvariabledefinitionid" > <attribute name="value" /> </link-entity> </entity> </fetch>
An improvement on the above is to make it an outer join and to also return the DefaultValue from the environment definition - then you have the ability to cater for if the environment variable is not set in an environment.
As the previous users mentioned, you can. A clean way if you want to avoid fetchXML is with the out-of-the-box client web api script, retrieveRecord.
Xrm.WebApi.retrieveRecord("environmentvariablevalue", <GUID>, "?$select=value").then(successCallback, errorCallback);
Note: the GUID of the environment variable value will be the same in the different environments if you imported the variable with a solution.
More info: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/retrieverecord
Hope this helps!
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.
In our never-ending quest to improve we are simplifying the forum hierarchy…
We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
WarrenBelz 793 Most Valuable Professional
Michael E. Gernaey 333 Super User 2025 Season 2
Power Platform 1919 268