Skip to main content

Notifications

Announcements

No record found.

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!

  • Suggested answer
    Bipin D365 Profile Picture
    28,981 Moderator on at
    RE: Sample Code to Invoke Canvas App from JavaScript, and Send Model-Driven App Form Fields to Display on Canvas App

    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/.../

  • Tanmay D365 Profile Picture
    30 on at
    RE: Sample Code to Invoke Canvas App from JavaScript, and Send Model-Driven App Form Fields to Display on Canvas App

    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!

  • Tanmay D365 Profile Picture
    30 on at
    RE: Sample Code to Invoke Canvas App from JavaScript, and Send Model-Driven App Form Fields to Display on Canvas App

    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.

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Sample Code to Invoke Canvas App from JavaScript, and Send Model-Driven App Form Fields to Display on Canvas App

    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
    RE: Sample Code to Invoke Canvas App from JavaScript, and Send Model-Driven App Form Fields to Display on Canvas App

    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

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans