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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

How to make the Canvas App id constant across environments?

(0) ShareShare
ReportReport
Posted on by 115

Hi,

I have an embedded canvas app in my development enviroment. When I export this app as a package and import it in my test environment, the App ID is getting changed. Because of this, I need to manually change the App ID in the form where I am using it. Is there any way to export the app with the same ID?

Thanks,

Madhan

I have the same question (0)
  • Gerard Verbruggen Profile Picture
    130 on at
    How to make the Canvas App id constant across environments?
    Hi All,
     
    I stumbled into the same thing and ended up solving it like this:
     
    Added a simple table where I store the APP id's per environment:
     
     
    And created a eventhandler to set the correct AppId for the current environment:
     
        [FormDataSourceEventHandler(formDataSourceStr(LedgerJournalTransVendInvoice, LedgerJournalTrans), FormDataSourceEventType::Activated)]
        public static void LedgerJournalTrans_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
        {
            FormRun formRun = sender.formRun();
            PowerAppsHost powerAppsHost = formRun.design(0).controlName("PowerAppsHost"); //Get the PowerApp control
            PowerAppsIds powerAppsIds; //Table holding the PowerAppID
    
            select firstonly powerAppsIds
                where powerAppsIds.Environment == XXX_General::checkEnvironment() 
                && powerAppsIds.AppName == @"Attachment";
           
            powerAppsHost.AppId(powerAppsIds.AppId);
        }
     
    That XXX_General::checkEnvironment():
     
        static XXX_Environments checkEnvironment()
        {
            var env = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory::GetApplicationEnvironment();
            XXX_Environments ret; //Enum holding Prod, UAT2, UAT1 and Other
    
            switch(env.Infrastructure.FullyQualifiedDomainName)
            {
                case "prodURL.operations.dynamics.com":
                    ret = XXX_Environments::Production;
                    break;
                case "UATURL.sandbox.operations.dynamics.com":
                    ret = XXX_Environments::UAT1;
                    break;
                case "PreProdURL.sandbox.operations.dynamics.com":
                    ret = XXX_Environments::UAT2;
                    break;
                default:
                    ret = XXX_Environments::Other;
                    break;
            }
    
            return ret;
        }
    Maybe this helps someone.
     
    Cheers,
    Gerard
     
  • Suggested answer
    Jelle_v Profile Picture
    45 on at
    RE: How to make the Canvas App id constant across environments?

    In my experience, when extending a modeldriven app with a canvas app, it is to provide some custom functionality. Therefore we start in our DEV organization. Creating the canvas app also in the DEV organization, causes the embedded canvas app to refer to the canvas appid of the DEV organization.

    Deploying both the modeldriven as the canvas app to another organization will generate new appids. When you test the embedded canvasapp, the initial canvas app is shown (from the dev environment) and seems fine.

    Since the canvas app is interacting back to the modeldriven app trough the "ModelDrivenFormIntegration", it updates my DEV organization.

    This is not the intended behaviour.

    I wrote a plugin that copies the correct appid(from a env variable) to a custom appid field on crate of my record. The canvasapp control has the appid bound to that appid field.

    It's not nice, it's a workaround, but it works.

  • SergioMarques Profile Picture
    on at
    RE: How to make the Canvas App id constant across environments?

    Hi Madhan,

    In practice, you shouldn't need to change the App Id in order for the embedded canvas app to work.

    Are you facing any specific error when you don't change it?

    Additionally, the user you are using when opening the form is a system admin? If not, can you check if the user has Organization level read permission to an entity called "Canvas App"?  

    Let me know the result of the testing and any feedback from this.

    Thank you.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 258

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 179

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 129 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans