Search code examples
javascriptc#dynamics-crm-2015

CRM Dynamics , How to pass values from one form and set the values in a new Entity(form) using Xrm.Utility.openEntityForm();


I have written a JavaScript function that opens a new Phone Call Entity form from ribbon button clicked in the Contact form. I have managed to pass open the new phone call, however I am battling toi find a way to set the values from contact in the nerw phone call form. Please view my code below

    function OpenPhoneCall()
    {
      Xrm.Utility.openEntityForm("phonecall",null,parameters);
    }

This works fine,it redirects to phone call and all, my challenge is passing values from the Contact to Phone Call entity, I saw examples that only set default values, I want to make it generic and set let it read the values in Contact and set them in the Phone Call form.

Please look at the full Code below to get the parameters from the Contact, now how do I set them in Phone Call:

function OpenPhoneCall() {

    var parameters = 
        {
            numberToDial:Xrm.Page.getAttribute("mobilephone").getValue(),
            mobileUserName :Xrm.Page.getAttribute("new_receivecallon").getValue(),
            mobileUserPassword: Xrm.Page.getAttribute("telephone1").getValue()
        };


    Xrm.Utility.openEntityForm("phonecall",null,parameters);
}

I would really appreciate some advice on how to archive this, as I see many examples on the net show how to set default values, NOTE: I am passing null for second parameter in the openEntityForm JS Method as I do not want to open an existing record, a new one. Thanks in advance.


Solution

  • Your code is correct, the error is in the field names in parameters.

    Example: open a phone call from a contact, grabbing the mobile number and using it as phone number of the activity:

    var params = {
        phonenumber: Xrm.Page.getAttribute('mobilephone').getValue()
    };
    Xrm.Utility.openEntityForm("phonecall", null, params);