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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Open and fill new form using JavaScript

(0) ShareShare
ReportReport
Posted on by 25

In my Opportunity entity I added a ribbon button that opens a new custom activity form (Minutes of Meeting).

Using JavaScript I want to automatically fill the Regarding field of the new activity pointing to the related Opportunity.

This is my function in the command file:

function openNewForm(){
	
var parameters = {};

var lookupVal = new Array();
lookupVal[0] = new Object();
lookupVal[0].id = Xrm.Page.data.entity.getId();
lookupVal[0].name = Xrm.Page.getAttribute("name").getValue();
lookupVal[0].entityType = "opportunity";
parameters["regardingobjectid"] = lookupVal;

var windowOptions = {
 openInNewWindow: true
};
Xrm.Utility.openEntityForm("adp_minutesofmeeting",null,parameters,windowOptions);
	
}

When I click on the button, a new windows opens but with no content, not even loading animation.

However if I modify the code and pass null parameters, the new Activity form opens successfully.

Is there anything missing in my code?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    What don't you use the OOTB mapping functionality?

  • sam hajjar Profile Picture
    25 on at

    Hey Guillaume,

    Thank you for your reply.

    What do you mean with OOTB mapping? without using JS?

  • Verified answer
    Community Member Profile Picture
    on at
  • sam hajjar Profile Picture
    25 on at

    Thank you Saad for your answer,

    Unfortunately It's still not working. This time I get an Error message when the new window tries to load.

    I tried to find the problem and narrowed it down to this:

    This works fine (No error whatsoever):

    function openNewForm()
    {
    var parameters = {};
    Xrm.Utility.openEntityForm("adp_minutesofmeeting",null,parameters,null);
    }


    This however creates an error:

    function openNewForm()
    {
    var parameters = {};
    parameters["testParam"] = "test";
    Xrm.Utility.openEntityForm("adp_minutesofmeeting",null,parameters,null);
    }


  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Is the actual parameter name correct? testparam? This should be the same as the field name on the form.

    For the lookups you have the multiple parameters of course.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    Exactly without JS like they do it here for lead and opportunity: itsolutions.bdo.ca/.../using-field-mapping-in-microsoft-dynamics-crm-to-copy-data-between-associated-records

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans