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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Sample Code to Invoke Canvas App from JavaScript, and Send Model-Driven App Form Fields to Display on Canvas App

(0) ShareShare
ReportReport
Posted on by 30

Hi,

I am looking for a code snippet that opens a Canvas App as an HTML web page, once the JavaScript file is executed.

And I want to copy field values from the model-driven app form, to the Canvas App, and display those fields on the Canvas App.

Thank you!

I have the same question (0)
  • Tanmay D365 Profile Picture
    30 on at

    Here is the code I have used.

    // JavaScript Code

    var CustomizeOpportunity = {

       sendOpportunityFields : function(executionContext)

       {

           debugger;

           var formContext = executionContext;

           var opportunityGuid = formContext.data.entity.getId();

           var opportunityTopic = formContext.getAttribute("name").getValue();

           // var opportunityCurrency = formContext.getAttribute("transactioncurrencyid").getValue();

           // var potentialCustomer = formContext.getAttribute("customerid").getValue();

           // var opportunityStatus = formContext.getAttribute("statecode").getValue();

           // var opportunityOwner = formContext.getAttribute("ownerid")

           alert(opportunityGuid + opportunityTopic);

           // Initializing Web Resource Parameter

           var pageInput = {

               pageType: "webresource",

               webresourceName: "cc2_html"

           };

           // Declaring HTML Page Dimensions

           var navigationOptions = {

               target: 2,

               width: 1050, // in pixels

               height: 900, // in pixels

               position: 1

           };

           XMLHttpRequest.Navigation.navigateTo(pageInput, navigationOptions).then(success,error);

               function success()

               {

                   console.log("successfully run")

               }

               function error(){

                   console.log("Error has occurred...")

               }

       }

    }

    //Html Code

    pastedimage1665844761049v2.png

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I believe VSCode's autocomplete tricked you. Try to use line

    Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(success,error);

    instead of line

    XMLHttpRequest.Navigation.navigateTo(pageInput, navigationOptions).then(success,error);

    in your code.

  • Tanmay D365 Profile Picture
    30 on at

    Thanks a lot!

    This worked, now the Canvas App is being opened.

    My next challenge is passing the model-driven app data, to the Canvas App. Is there any way that it could be done?

    I would like to display the field values passed, within a Canvas App form and give the user an option to update those values.

  • Tanmay D365 Profile Picture
    30 on at

    Also, is there any special syntax to be used for Lookup or Choice columns?

    Will I have to use Filter(), Lookup() or any of those types of functions?

    My app is opening as an HTML page but now I would like to pass the form field values from the model driven app to the canvas app.

    Would be nice if you could show how that can be done.

    Thanks!

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hi,

    You can only pass record Id from model driven app to canvas app.

    You will then need to use record Id to fetch other details using filter/lookup method

    dynatecon.com/.../

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 172

#2
ManoVerse Profile Picture

ManoVerse 58 Super User 2026 Season 1

#3
Niki Patel Profile Picture

Niki Patel 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans