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

Announcements

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Environment variable

(1) ShareShare
ReportReport
Posted on by 7
We have a specific value for each environment that should be set on account and lead form.
Does anyone have an example Javascript to achieve this?
I have the same question (0)
  • Luis Arellano Profile Picture
    36 on at
     
    If you want to use the function it is a little more complicated:
    https://{yourOrg}.crm.dynamics.com/api/data/v9.2/RetrieveEnvironmentVariableValue(DefinitionSchemaName='{envVariableSchemaName}')
     
    Using Xrm.WebApi you have to include the metadata, following Microsoft's examples:
    var Sdk = window.Sdk || {};
    
    Sdk.RetrieveEnvironmentVariableValueRequest = function(DefinitionSchemaName) {
        this.DefinitionSchemaName = DefinitionSchemaName;
    };
    
    // NOTE: The getMetadata property should be attached to the function prototype instead of the
    // function object itself.
    Sdk.RetrieveEnvironmentVariableValueRequest.prototype.getMetadata = function () {
        return {
            boundParameter: null, // not boud function
            operationName: "RetrieveEnvironmentVariableValue",
            operationType: 1, // because it is a function
            parameterTypes: {
                "DefinitionSchemaName": { // Parameter name
                    "typeName": "Edm.String", // Copy the type from the parameter in the function's Microsoft learn page
                    "structuralProperty": 1 // Primitive type, we are looking for a string which is the environment variable name
                }
            },
        };
    };
    
    var retrieveEnvironmentVariableValueRequest = new Sdk.RetrieveEnvironmentVariableValueRequest("{envVariableSchemaName}"); 
    
    Xrm.WebApi.online.execute(retrieveEnvironmentVariableValueRequest).then(function (response) {
        if (response.ok) {
            return response.json(); // handle the promise result, you can either return or use the .then method
        }
    })
    .catch(function(error) {
          debugger; console.log(error.message);
        // handle error conditions
    });
     
    Your promise result should look like this
     
     
     
     
     
    If you are OK querying the table directly, you can take a look at these 2 posts.
     
    It is a regular XrmWebApi/rest call to the table
    environmentvariabledefinition
     
    I am copying one of the snippets shown in the first link
     
    async GetEnvironmentVariableValue  function (name) {
        let results = await Xrm.WebApi.retrieveMultipleRecords("environmentvariabledefinition", `?$filter=schemaname eq '${name}'&$select=environmentvariabledefinitionid&$expand=environmentvariabledefinition_environmentvariablevalue($select=value)`);
    
        if (!results || !results.entities || results.entities.length < 1) return null;
        let variable = results.entities[0];
        if (!variable.environmentvariabledefinition_environmentvariablevalue || variable.environmentvariabledefinition_environmentvariablevalue.length < 1) return null;
    
        return variable.environmentvariabledefinition_environmentvariablevalue[0].value;
    }
     
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 56 Super User 2026 Season 1

#2
Eugen Podkorytov Profile Picture

Eugen Podkorytov 49

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 42 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans