Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Map retrieved data to quick create form

Posted on by 105

I have a ribbon button that retrieves data from api for the selected record and then opens the quick create form. How do i autofill this quick create form with the data retrieved from api? 

  • Verified answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 5,769 Super User on at
    RE: Map retrieved data to quick create form

    Hello,

    Yes you can implement using "Xrm.Navigation.openForm" API. Just need some tweaks as per your logic.

    First of all you need to have a trigger point because without it you will not able to open the form.

    Then as you said you have the data from the API call, use this data and store it in an object and pass it to the "Xrm.Navigation.openForm" API.

    This API will open the quick create form and populate the data in that form.

    Lets say in below example you can see I have added a button on the account form and when a user will click on this button below JS will be called. This JS will open Contact quick create form and populate the data which I have provided(in your case replace this data with API data).

    pastedimage1652968649819v1.png

    function setField()
    {
        var entityFormOptions = {};
        entityFormOptions["entityName"] = "contact";
        entityFormOptions["useQuickCreateForm"] = true;
    
        // Set default values for the Contact form
        var formParameters = {};
        formParameters["firstname"] = "Sample";
        formParameters["lastname"] = "Contact";
        formParameters["fullname"] = "Sample Contact";
        formParameters["emailaddress1"] = "contact@adventure-works.com";
        formParameters["jobtitle"] = "Sr. Marketing Manager";
        formParameters["donotemail"] = "1";
        formParameters["description"] = "Default values for this record were set programmatically.";
    
        // Set lookup column
        formParameters["preferredsystemuserid"] = "279247f4-b5cd-ec11-a7b5-6045bd002bf6"; // ID of the user.
        formParameters["preferredsystemuseridname"] = " Admin user"; // Name of the user.
        formParameters["preferredsystemuseridtype"] = "systemuser"; // Table name.
        // End of set lookup column
    
        // Open the form.
        Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
            function (success) {
                console.log(success);
            },
            function (error) {
                console.log(error);
            });
    }

    Also it will only populate those fields which are present on the form(in my case owner was not present on the form. so it will be not populated but you can refer and check how you can populate the lookup)

    pastedimage1652968725671v2.png

    docs.microsoft.com/.../openform

    Thank you,

    Amit katariya

  • sjov Profile Picture
    sjov 105 on at
    RE: Map retrieved data to quick create form

    Thanks, but I would like the fields to be automatically filled with the data retrieved from api.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,960 Super User on at
    RE: Map retrieved data to quick create form

    Hello,

    You can try below code to prefill some of the field while opening Quick create form -

    var entityFormOptions = {};

    entityFormOptions["entityName"] = "contact";

    entityFormOptions["useQuickCreateForm"] = true;

    // Set default values for the Contact form

    var formParameters = {};

    formParameters["firstname"] = "Sample";

    formParameters["lastname"] = "Contact";

    formParameters["fullname"] = "Sample Contact";

    formParameters["emailaddress1"] = "contact@adventure-works.com";

    formParameters["jobtitle"] = "Sr. Marketing Manager";

    formParameters["donotemail"] = "1";

    formParameters["description"] = "Default values for this record were set programmatically.";

    // Set lookup column

    formParameters["preferredsystemuserid"] = "3493e403-fc0c-eb11-a813-002248e258e0"; // ID of the user.

    formParameters["preferredsystemuseridname"] = " Admin user"; // Name of the user.

    formParameters["preferredsystemuseridtype"] = "systemuser"; // Table name.

    // End of set lookup column

    // Open the form.

    Xrm.Navigation.openForm(entityFormOptions, formParameters).then(

       function (success) {

           console.log(success);

       },

       function (error) {

           console.log(error);

       });

    docs.microsoft.com/.../openform

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,995 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,610 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans