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)

Mapping parameters when opening a new form

(0) ShareShare
ReportReport
Posted on by

Hi experts,

I have 2 case form called Apple Case and Samsung Case. 

In the account form, I have a dropdown field called new_unit with values Apple and Samsung. Based on the value chosen, the corresponding form opens from the subgrid + button. I customized the command of the button from the ribbon workbench to modify the behavior. 

Screen-Shot-2018_2D00_05_2D00_31-at-1.07.58-PM.png

Although the correct form is opening, the fields are not being mapped from account to case. I tried using the parameters["customerid"] = name; method but it doesn't work. Please find my code below and suggest what I can do to map the fields as its very important. 

function OpenCase() {

    var formId = Xrm.Page.ui.formSelector.getCurrentItem().getId();
    var unit = Xrm.Page.getAttribute("new_unit").getValue();
    var name = Xrm.Page.getAttribute("name").getValue();
  alert(name);
    if(unit == "100000000")
    {
        var parameters = {};
        parameters["customerid"] = name;
        parameters["formid"] = "4a63c8d1-6c1e-48ec-9db4-3e6c7155334c";  //replace Form C ID
        Xrm.Utility.openEntityForm("incident", null, parameters);
    }
    else
    {
        var parameters = {};
        parameters["customerid"] = name;
        parameters["formid"] = "13d6c837-5edb-4e33-9672-60650f6cf1ef"; // replace Form D ID
        Xrm.Utility.openEntityForm("incident", null, parameters);
    }
}


Thanks,

Jon

*This post is locked for comments

I have the same question (0)
  • Shidin Haridas Profile Picture
    3,497 on at

    For lookup names, you need to pass the record id and name as well, in addition:

    Here is a helper function to set the LookUp values:

    function setLookup (fieldName, fieldType, fieldId, value) {
    try {
    var object = new Array();
    object[0] = new Object();
    object[0].id = fieldId;
    object[0].name = value;
    object[0].entityType = fieldType;
    formContext.getAttribute(fieldName).setValue(object);
    }
    catch (e) {
    alert("Error in SetLookUp:" + e.message);
    }
    },

    In your case, you need to call the function as follows:

    setLookup("customerid", "account", accountGuid, accountName)

    If this answer helps you, please mark it as verified.

    Cheers!

  • Community Member Profile Picture
    on at

    Hi Shidin,

    Unfortunately, I dont understand your code.

    If you could suggest what changes I have to make to my code to map a field(lookup and a simple field), it would be very helpful.

    Thanks,

    Jon

  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi Jon,

    refer to below link on how to set lookup field using openEntityForm.

    [View:https://msdn.microsoft.com/en-us/library/gg334375.aspx#BKMK_ExampleXrmUtilityOpentEntityForm:750:50]

    sample

    parameters["customerid"] = "2878282E-94D6-E111-9B1D-00155D9D700B";   // Guid

    parameters["customeridname"] = "Contoso";                                                   // Name

    parameters["customeridtype"] = "account";                                                         // Entity Name

  • Community Member Profile Picture
    on at

    Hi Wei Jei,

    Thank you for your reply.

    I dont want to hardcode the values into the field. Instead I want to dynamically assign these values.

    I just tried this approach and it is working for simple fields but not lookup field (account name > customerid).

    How can I modify my code so that it works for lookup fields as well?

    function OpenCase() {
    
        var formId = Xrm.Page.ui.formSelector.getCurrentItem().getId();
        var unit = Xrm.Page.getAttribute("new_unit").getValue();
        var name = Xrm.Page.getAttribute("name").getValue();
      alert(name);
        if(unit == "100000000")
        {
            var parameters = {
    customerid: Xrm.Page.getAttribute("name").getValue(), //this line causing error
    new_symbol: Xrm.Page.getAttribute("tickersymbol").getValue()
    };
            //parameters["customerid"] = "Datum Child 2";
            parameters["formid"] = "4a63c8d1-6c1e-48ec-9db4-3e6c7155334c";  //replace Form C ID
            Xrm.Utility.openEntityForm("incident", null, parameters);
        }
        else
        {
            var parameters = {
    customerid: Xrm.Page.getAttribute("name").getValue(), //this line causing error
    new_symbol: Xrm.Page.getAttribute("tickersymbol").getValue()
    };
            //parameters["customerid"] = "Datum Child 2";
            parameters["formid"] = "13d6c837-5edb-4e33-9672-60650f6cf1ef"; // replace Form D ID
            Xrm.Utility.openEntityForm("incident", null, parameters);
        }
    }


    Thanks,

    Jon

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Jon ,

    Try with this -I have not tried , so let me know if you are getting any issue.

    function OpenCase() {
    
        var formId = Xrm.Page.ui.formSelector.getCurrentItem().getId();
        var unit = Xrm.Page.getAttribute("new_unit").getValue();
        var name = Xrm.Page.getAttribute("name").getValue();
        alert(name);
        if (unit == "100000000") {
            var parameters = {};
            //parameters["customerid"] = "Datum Child 2";
            parameters["formid"] = "4a63c8d1-6c1e-48ec-9db4-3e6c7155334c";  //replace Form C ID
    
            parameters["customerid"] = Xrm.Page.data.entity.getId().replace('{', "").replace("}", "");
            parameters["customeridname"] = Xrm.Page.getAttribute("name").getValue();
            parameters["customeridtype"] = Xrm.Page.data.entity.getEntityName();;
    
            Xrm.Utility.openEntityForm("incident", null, parameters);
        }
        else {
            var parameters = {};   
            parameters["formid"] = "13d6c837-5edb-4e33-9672-60650f6cf1ef"; // replace Form D ID
         
            parameters["customerid"] = Xrm.Page.data.entity.getId().replace('{', "").replace("}", "");
            parameters["customeridname"] = Xrm.Page.getAttribute("name").getValue();
            parameters["customeridtype"] = Xrm.Page.data.entity.getEntityName();;
    
        
            Xrm.Utility.openEntityForm("incident", null, parameters);
        }
    }
    
  • Community Member Profile Picture
    on at

    Hi Goutam,

    That worked!! Just one more question. How would I do the same to map simple fields such as text fields, optionset fields, etc?

    In my reply above, I used and it was working.

    var parameters = {
    new_symbol: Xrm.Page.getAttribute("tickersymbol").getValue()
    };

    But since in your code, you are declaring it as parameters["fieldname"], how would I do it?

    Thanks,

    Jon

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Jon,

    Exactly similar for other field only use the field name in the parameters object .

    try to pass like below -

    /*String*/
    parameters["firstname"] = "John"; // Field Name is firstname which is single line text
    


    /*Option set 1: Male, 2: female*/
     parameters["gendercode"] = "1";

    So your code should be like this -only add in next line of the lookup.

    parameters["new_symbol"] = Xrm.Page.getAttribute("tickersymbol").getValue(); 

    You will  get more details in below article  - 

    https://community.dynamics.com/crm/b/mscrmcustomization/archive/2016/10/25/xrm-utility-functions-openentityform

  • Community Member Profile Picture
    on at

    Hi Goutam,

    Thank you for the explanation. Now I understand it so much better.

    Best,

    Jon

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