Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Prepopulating Data in Form when opening form using Xrm.Navigation.navigateTo

(0) ShareShare
ReportReport
Posted on by

Hello,

Is there a way to pass the parameters and access them from onload of the form to the Xrm.Navigation.navigateTo({pageType:”entityrecord”, entityName:”contact”, formType:2}  or send data to auto populate the data when the form opens in the modal likewise we have it in the Xrm.Navigation.Openform?

  • Suggested answer
    Linn Zaw Win Profile Picture
    on at
    Prepopulating Data in Form when opening form using Xrm.Navigation.navigateTo
    I have written a blog post about it with code example for setting fields with various data types, including lookup and partylist.
  • Suggested answer
    Nils Goldenstein Profile Picture
    on at
    RE: Prepopulating Data in Form when opening form using Xrm.Navigation.navigateTo

    If you want to have a step by step guide how to populate data into a form using the "navigateTo()" function, please feel free to have a look at this blog entry:

    nilsgoldenstein.com/how-to-populate-data-into-navigateto

  • Suggested answer
    tayurskiy Profile Picture
    on at
    RE: Prepopulating Data in Form when opening form using Xrm.Navigation.navigateTo

    Data is a dictionary object, not a string. Below code works for me.

    data: {

    attribute1: 'value1',

    attribute2; 'value2'

    }

  • Suggested answer
    Amit Katariya007 Profile Picture
    Super User 2025 Season 1 on at
    RE: Prepopulating Data in Form when opening form using Xrm.Navigation.navigateTo

    Hello Ravi,

    You can use 'openForm' function which will help you to open a quick create form.

    learn.microsoft.com/.../openform

    Thank you,

    Amit Katariya

  • RaviKashyap Profile Picture
    Moderator on at
    RE: Prepopulating Data in Form when opening form using Xrm.Navigation.navigateTo

    Does anyone got this working?

    I am opening new/ create form using Xrm.naigation.navigateto but unable to pass data parameter successfully 

      var pageProperty = {
                pageType: "entityrecord",
                entityName: "account",
                formType: 2,
                data: ???? // what need to goes here if I need to set name or primarycontact on account
            };
    
            var navigationProperty = {
                target: 2,
                width: { value: 80, unit: "%" },
                position: 1
            };
            Xrm.Navigation.navigateTo(pageProperty, navigationProperty);

  • Clint Woods Profile Picture
    on at
    RE: Prepopulating Data in Form when opening form using Xrm.Navigation.navigateTo

    This works

    function LaunchMyForm() {
        var extraqs = {};
        extraqs["new_firstname"] = GetText(_formContext, "firstname");
        extraqs["new_lastname"] = GetText(_formContext, "lastname");
        extraqs["new_mobilephone"] = GetText(_formContext, "mobilephone");
        extraqs["new_city"] = GetText(_formContext, "address1_city");
        extraqs["new_homephone"] = GetText(_formContext, "telephone2");
        extraqs["new_otherphone"] = GetText(_formContext, "telephone1");
        extraqs["new_personalemail"] = GetText(_formContext, "emailaddress2");
        extraqs["new_state"] = GetText(_formContext, "address1_city");
        extraqs["new_zippostalcode"] = GetText(_formContext, "address1_postalcode");

        var pageInput = {
            pageType: "entityrecord",
            entityName: "new_myform",
            createFromEntity: "",
            data: extraqs
        };
        var navigationOptions = {
            target: 2, // 2 is for opening the page as a dialog; 1 is inline
            height: { value: 80, unit: "%" },
            width: { value: 80, unit: "%" },
            position: 1    // 1: Center. 2: on the side
        };
        Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
            function success() { }, //A function to execute on successful navigation to the page when navigating inline and on closing the dialog when navigating to a dialog.
            function error() { }    //A function to execute when the operation fails.
        );
    }

    where GetTest() ==


    function GetText(formContext, attributeName) {
        var textValue = "";
        try {
            var oAttribute = formContext.data.entity.attributes.get(attributeName);
            if (oAttribute !== null) {
                textValue = oAttribute.getValue();
            }
        }
        catch (err) { /*do nothing*/ }

        return textValue === null ? "" : textValue;
    }

  • Suggested answer
    Henry J. Profile Picture
    on at
    RE: Prepopulating Data in Form when opening form using Xrm.Navigation.navigateTo

    Hi Vamsi,

    I don't see the "data" parameter in your code?

    It's required to pass parameters:

    data: (Optional) Object. A dictionary object that passes extra parameters to the form. Invalid parameters will cause an error.
    For information about passing parameters to a form, see Set field values using parameters passed to a form and Configure a form to accept custom querystring parameters.

    Henry

  • Vamsi Duggineni Profile Picture
    on at
    RE: Prepopulating Data in Form when opening form using Xrm.Navigation.navigateTo

    Thanks for that info henry. Actually I have tried some thing like below but no luck ?

    Any thing missing or is it actually correct way of passing ?

      var formParameters = {};
                        formParameters["fieldname"]  = id;
                   Xrm.Navigation.navigateTo({pageType:"entityrecord"entityName:"Entityname"formType:2formParameters}, {target: 2position: 1width: {value: 50unit:"%"}});
  • Suggested answer
    Henry J. Profile Picture
    on at
    RE: Prepopulating Data in Form when opening form using Xrm.Navigation.navigateTo

    Hi Vamsi,

    Yes, navigateTo supports passing parameters.The docs page hasn't been updated yet to document how, yet.

    I've obtained a draft of the new docs page, where the "data" parameter is mentioned.
    Please use at your own risk while the docs page gets officially updated:

    Parameters

    TABLE 1
    Name Type Required Description
    pageInput Object Yes

    Input about the page to navigate to. The object definition changes depending on the type of page to navigate to: entity list, entity record, or HTML web resource.

    ----------------------------------------------------------------

    entity list

    The object contains the following attributes:

    • pageType: String. Specify "entitylist".
    • entityName: String. The logical name of the entity to load in the list control.
    • viewId: (Optional) String. The ID of the view to load. If you don't specify it, navigates to the default main view for the entity.
    • viewType: (Optional) String. Type of view to load. Specify "savedquery" or "userquery".

    ----------------------------------------------------------------

    entity record

    The object contains the following attributes:

    • pageType: String. Specify "entityrecord".
    • entityName: String. Logical name of the entity to display the form for.
    • entityId: (Optional) String. ID of the entity record to display the form for. If you don't specify this value, the form will be opened in create-record mode.
    • createFromEntity: (Optional) Lookup. Designates a record that will provide default values based on mapped attribute values. The lookup object has the following String properties: entityType, id, and name (optional).
    • data: (Optional) Object. A dictionary object that passes extra parameters to the form. Invalid parameters will cause an error.
      For information about passing parameters to a form, see Set field values using parameters passed to a form and Configure a form to accept custom querystring parameters.
    • formId: (Optional) String. ID of the form instance to be displayed.
    • isCrossEntityNavigate: (Optional) Boolean. Indicates whether the form is navigated to from a different entity using cross-entity business process flow.
    • isOfflineSyncError: (Optional) Boolean. Indicates whether there are any offline sync errors.
    • processId: (Optional) String. ID of the business process to be displayed on the form.
    • processInstanceId: (Optional) String. ID of the business process instance to be displayed on the form.
    • relationship: (Optional) Object. Define a relationship object to display the related records on the form. The object has the following attributes.              
      TABLE 2
      Name Type Description
      attributeName String Name of the attribute used for relationship.
      name String Name of the relationship.
      navigationPropertyName String Name of the navigation property for this relationship.
      relationshipType Number Relationship type. Specify one of the following values:
      • 0:OneToMany
      • 1:ManyToMany
      roleType Number Role type in relationship. Specify one of the following values:
      • 1:Referencing
      • 2:AssociationEntity
    • selectedStageId: (Optional) String. ID of the selected stage in business process instance.

    ----------------------------------------------------------------

    HTML web resource

    The object contains the following attributes:

    • pageType: String. Specify "webresource".
    • webresourceName: String. The name of the web resource to load.
    • data: (Optional) String. The data to pass to the web resource.
    navigationOptions Object No

    Options for navigating to a page: whether to open inline or in a dialog. If you don't specify this parameter, page is opened inline by default. The object contains the following attributes:

    • target: Number. Specify 1 to open the page inline; 2 to open the page in a dialog. Also, rest of the attributes (width, height, and position) are valid only if you have specified 2 in this attribute (open page in a dialog).

      NOTE: Entity lists can only be opened inline; entity records and web resources can be opened either inline or in a dialog.

    • width: (Optional) Number or Object. The width of dialog. To specify the width in pixels, just type a numeric value. To specify the width in percentage, specify an object of type SizeValue with the following properties:
      • value: Number. The numerical value.
      • unit: String. The unit of measurement. Specify "%" or "px". Default value is "px".
    • height: (Optional) Number or Object. The height of dialog. To specify the height in pixels, just type a numeric value. To specify the width in percentage, specify an object of type SizeValue with the following properties:
      • value: Number. The numerical value.
      • unit: String. The unit of measurement. Specify "%" or "px". Default value is "px".
    • position: (Optional) Number. Specify 1 to open the dialog in center; 2 to open the dialog on the side. Default is 1 (center).
    successCallback function No

    A function to execute on successful navigation to the page when navigating inline and on closing the dialog when navigating to a dialog.

    errorCallback Function No

    A function to execute when the operation fails.

     

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

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

Overall leaderboard

Product updates

Dynamics 365 release plans