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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Javascript to open a related quick-create form

(0) ShareShare
ReportReport
Posted on by 19

Hello,

I've been working on a javascript snippet that when you click on a button from the ribbon, it opens new quick create form for a related record. It is a custom entity, and I've created a 1:N relationship, where the Opportunity can have many of these "contact attempt" records tied to it. I'm super close with the code, but I cannot get the related opportunity to populate on the form. When you click the button on an opportunity's ribbon, it should populate that opportunity into the form, but It opens without that value every time. I've worked through a couple of suggestions here in the forum, including adding an onload action (based on this: https://butenko.pro/2020/09/15/js-how-to-get-the-originating-record-reference-in-the-form-script-of-the-quick-create-form/) and using the XRM open form utility (following this: https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg334375(v=crm.8)) But it's just not working. 

Below is my code snippet. Any help/ideas would be appreciated. (aaaaa = replacing the company name in the code)

function contactAttemptQC() {    var entityFormOptions = {};
entityFormOptions["entityName"] = "aaaaa_contactattempt";
entityFormOptions["useQuickCreateForm"] = true;

var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0');
var yyyy = today.getFullYear();

var formParameters = {};
formParameters["name"] = "Contact Attempt";
formParameters["aaaaa_contactdate"] = today;

// Set lookup column
formParameters["aaaaa_attemptsid"] = "parentRecordReference.id";
formParameters["aaaaa_attemptsidname"] = "parentRecordReference.name";


// Open the form.
Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
function (success) {
console.log(success);
},
function (error) {
console.log(error);
});
}
I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    I think the problem here:

    formParameters["aaaaa_attemptsid"] = "parentRecordReference.id";

       formParameters["aaaaa_attemptsidname"] = "parentRecordReference.name";

    because I can't see this value (parentRecordReference) coming from where?

  • tonigcrm Profile Picture
    19 on at

    Yes, that was from an on create web resource that didn't work. I've now reworked it without it. below is my new code:

    function contactAttemptQC(primaryControl) {

    var formContext = primaryControl;
    var recordGuid = formContext.data.entity.getId().replace("{", "").replace("}", "");
    var recordName = formContext.getAttribute("Topic").getValue();

    var entityFormOptions = {};
    entityFormOptions["entityName"] = "aaaaa_contactattempt";
    entityFormOptions["useQuickCreateForm"] = true;


    var today = new Date();
    var dd = String(today.getDate()).padStart(2, '0');
    var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
    var yyyy = today.getFullYear();


    // Set default values for the Contact form
    var formParameters = {};
    formParameters["name"] = "Contact Attempt";
    formParameters["aaaaa_contactdate"] = today;


    // Set lookup column
    formParameters["aaaaa_attemptsid"] = recordGuid;
    formParameters["aaaaa_attemptsidname"] = recordName; 


    // Open the form.
    Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
    function (success) {
    console.log(success);
    },
    function (error) {
    console.log(error);
    });
    }

  • tonigcrm Profile Picture
    19 on at

    Ok, figured it out. You have to pass an array of info to do a set regarding. Below is my code in case anyone else wants to do something similar!

    function contactAttemptQC(primaryControl) {

       var formContext = primaryControl;

       var recordGuid = formContext.data.entity.getId().replace("{", "").replace("}", "");

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

       var recordType = "opportunity"

       var entityFormOptions = {};

       entityFormOptions["entityName"] = "aaaaa_contactattempt";

       entityFormOptions["useQuickCreateForm"] = true;

       var today = new Date();

       var dd = String(today.getDate()).padStart(2, '0');

       var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!

       var yyyy = today.getFullYear();

       // Set default values for the Contact form

       var formParameters = {};

       formParameters["name"] = "Contact Attempt";

       formParameters["aaaaa_contactdate"] = today;

       // Set lookup column

       formParameters["aaaaa_attempts"] = [{ id: recordGuid, name: recordName, entityType: recordType }];

       // Open the form.

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

           function (success) {

               console.log(success);

           },

           function (error) {

               console.log(error);

           });

    }

  • HandyK Profile Picture
    10 on at

    I have spent hours on this, foolishly following the Microsoft docs. You are an absolute champion - the lookup as an array saved my sanity. Thank you, Toni G!

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 > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 165

#2
ManoVerse Profile Picture

ManoVerse 156 Super User 2026 Season 1

#3
Zhilan Profile Picture

Zhilan 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans