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)

How to Pass Values between form using javascript

(0) ShareShare
ReportReport
Posted on by

I need to pass values from contact form to a custom activity  but not very sure how best to do this

below is what i have but its not working.

In the contact form on load event i have created the following function

function loadActivity() {

    var parameters = {};

    var contactid = Xrm.Page.data.entity.getId();

    parameters["contactid_0"] = contactid;
    Xrm.Utility.openEntityForm("new_testActivityForm", null, parameters);

}

Then in the custom activity form(new_testActivityForm), I want to populate the fields, Regarding Contact, DOB, FullName
I have created a parameter called contactid_0 on the custom activity form(new_testActivityForm) then created the following in the new_testActivityForm form load event


function getQuerystring(key, default_) {

    if (default_ == null) default_ = "";

    key = key.replace(/[[]/, "\[").replace(/[]]/, "\]");

    var regex = new RegExp("[\?&]" + key + "=([^&#]*)");

    var qs = regex.exec(window.location.href);

    if (qs == null)

        return default_;

    else

        return qs[1];

}


function populateActivity() {

    if (getQuerystring('contactid_0') != "") {

        var contactid = getQuerystring('contactid_0');

        contactid = contactid.substr(3, 32);

       

    }

}

how do i make this to work, return the values and populate the activity form with Regarding Contact, DOB, FullName

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Royal King Profile Picture
    27,686 on at

    You can't set regarding field value by passing parameter value to Xrm.Utility.openEntityForm method

    you can find this information here 
    http://msdn.microsoft.com/en-us/library/gg334375.aspx


    "You can’t set the values for partylist or regarding lookups."

    So to pass regarding Object id,name and type , you can add three custom parameters to
    your activity entity Like below and save ,publish the entity.


    Once you have custom parameters added to the entity you can pass values to these parameters using below script and you can access same in the new entity form.

    function openActivity() {

    var parameters = {};
    parameters["regardingobjectid_1"] = Xrm.Page.data.entity.getId();
    parameters["regardingobjectidname_1"] = Xrm.Page.data.entity.getPrimaryAttributeValue()
    parameters["regardingobjectidtype_1"] = Xrm.Page.data.entity.getEntityName();

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

    you can retrieve these custom parameters in opened entity form using below code

    function getCustomParam(){

    if ( Xrm.Page.context.getQueryStringParameters().regardingobjectid_1 != null &&  Xrm.Page.context.getQueryStringParameters().regardingobjectid_1 != 'undefined' )

    {

     var recorid = Xrm.Page.context.getQueryStringParameters().regardingobjectid_1 ;

    var recordname  = Xrm.Page.context.getQueryStringParameters().regardingobjectidname_1;

    var entityname = Xrm.Page.context.getQueryStringParameters().regardingobjectidtype_1;

    Xrm.page.getAttribute("regardingobjectid").setValue( [{ id: recorid, name: recordname, entityType: entityname}] );

    }

    }

  • Community Member Profile Picture
    on at

    Thanks Chitra. Thats exactly what i was looking for and it works fine. Many thanks

  • KG_CRM Profile Picture
    on at

    Hi Chitra,

    I'm trying to figure this out as well, but I believe your quote of "You can’t set the values for partylist or regarding lookups." is taken a little out of context.  Just before the list of bullet points that says this, the article says "The following guidelines apply when setting the value of a lookup on a form using a query string argument:"  So partylist and regarding field types can't be set when using a query string which I believe are the URL methods shown on the page for creating & opening new records, but it does not say they can't be set using Xrm.Utility.openEntityForm.

    However the method you suggested is also mentioned at the link below.

    https://mscrmmindfire.wordpress.com/2013/12/04/crm-2013-passing-custom-parameters-to-openentityform-function/

    Another option might be http://a33ik.blogspot.com/2013/01/open-new-activity-form-with-regarding.html, but I have not tried this yet myself.  The "record type codes" mentioned here I believe refer to https://msdn.microsoft.com/en-us/library/bb887791.aspx.

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