locked
How to show a value from one form to another? RRS feed

  • Question

  • In CRM 2011, I have some custom fields in contact form. After clicking on any specific contact i will go to Contract form for that particular contact.

    I want to show some of the fields value of contact to the Contract form.

    eg: I have "Broker Name" for a particular contact. Now I am opening the contract form for that particular contact and I have a read only custom field in contract form which will show the Broker Name for that particular contact.

    How I will do this?

     

    Thanks & Regards

    Ayan Choudhury

    Friday, December 23, 2011 4:54 AM

Answers

  • This problem is solved, Thanks sandeep but the code provided by you is not required in my case. I am giving the exact Jscript code what i have done and now it is running successfully.

     

    function AlertText() { 

    var primaryContactName = Xrm.Page.data.entity.attributes.get("new_contactname").getValue()[0].name; 

    var primaryContactID = Xrm.Page.data.entity.attributes.get("new_contactname").getValue()[0].id; 

    var brokernameTEMP = RetrieveEntityById("contact", primaryContactID, "new_broker");

    var brokername = RetrieveEntityById("contact", brokernameTEMP, "fullname");

    Xrm.Page.data.entity.attributes.get("new_brokername").setValue(brokername);

    }

     

     

     

    function RetrieveEntityById(EmployeeEntityName, EmployeeId, NameFieldAttributeName) {

     

        var resultXml;

        var AttributeVal = null;

        var errorCount;

        var msg;

        var xmlHttpRequest;

        var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();

     

        //Prepare the SOAP message.

        var xml = "<?xml version='1.0' encoding='utf-8'?>" +

       "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +

       " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +

       " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +

       authenticationHeader +

       "<soap:Body>" +

       "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +

       "<entityName>" + EmployeeEntityName + "</entityName>" +

       "<id>" + EmployeeId + "</id>" +

       "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +

       "<q1:Attributes>" +

     

      "<q1:Attribute>" + NameFieldAttributeName + "</q1:Attribute>" +

       "</q1:Attributes>" +

       "</columnSet>" +

       "</Retrieve></soap:Body></soap:Envelope>";

     

        //call function to create Soap Request to ms crm webservice

        xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

        xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);

        xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");

        xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

        xmlHttpRequest.setRequestHeader("Content-Length", xml.length);

        xmlHttpRequest.send(xml);

     

        resultXml = xmlHttpRequest.responseXML;

     

        var errorCount = resultXml.selectNodes('//error').length;

     

        if (errorCount != 0) {

            var msg = resultXml.selectSingleNode('//description').nodeTypedValue; //Process and display the results.

            alert("Error occured: " + msg);

        }

        else {

            if (resultXml.selectSingleNode('//q1:' + NameFieldAttributeName) != null) {

                AttributeVal = resultXml.selectSingleNode('//q1:' + NameFieldAttributeName).nodeTypedValue;

            }

        }

        return AttributeVal;

    }

     

     

    Regards,

    Ayan Choudhury

    ------------------------------------------------------------------

    If you found this as helpful please Vote as Helpful

    • Marked as answer by aanch Friday, December 30, 2011 7:09 AM
    Friday, December 30, 2011 7:09 AM

All replies

  • hii you need to create realtion ship,

    1:N on contact.


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by san Sanz Friday, December 23, 2011 7:37 AM
    Friday, December 23, 2011 7:36 AM
  • Thanks Sanz

    but I am new in CRM so will you please elaborate the steps......

    I will create a new relationship, but how i will post that particular broker name to the CONTACT form.

     

    Thanks & Regards

    Ayan Choudhury

    Friday, December 23, 2011 9:08 AM
  • Hi ayan,

    I am sorry the relation is already existed in crm,

    and one major thing is

    One Contact  approaches many contracts(brokers)

    and at the same time one contract has many customers(contacts)

    please check below image to how to check contracts for a particular contact.

     

     

     


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by san Sanz Friday, December 23, 2011 9:26 AM
    Friday, December 23, 2011 9:26 AM
  • Thanks Sandeep(I think SAN = Sandeep)

    I think you are not getting my point. Please look below:

    I have contact named Test Contact1 which have a broker Ayan Choudhury which i can select from the contact form.

    Now i am going to Transaction form(I have renamed the Contract form to Transaction) for that particular contact named Test Contact1 in there Broker is read only field which will populate with that Broker Name(I mean to say with Ayan Choudhury).

    How will populate this automatically.

     

    Thanks & Regards

    Ayan Choudhury

    Friday, December 23, 2011 10:11 AM
  • hi ayan ,

    Please click on Contracts(transactions) at left navigation,

    click on Add New contract it will automatically populate

     


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Friday, December 23, 2011 10:18 AM
  • That's the thing, the broker name is not coming automatically.

    May be i have to create a new relationship as you suggested previously. Let me try with that.

    Friday, December 23, 2011 10:26 AM
  • hi ayan,

    You can add a mapping on relationship "Contact to Contract" to populate automatically the attribute "Broker".

    Regards,


    Philippe

    Blog : Dynamics CRM pour les francophones

    Please remember to click "Vote as Helpful" and “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Proposed as answer by Philippe LEAL Friday, December 23, 2011 10:30 AM
    Friday, December 23, 2011 10:30 AM
  • Thanks Philippe,

     

    • Which will be the primary entity for this relation? I am getting the name from contact entity to my transaction(contract) entity

     

     

    Regards

    Ayan Choudhury

    Friday, December 23, 2011 10:46 AM
  • Hi ayan,

    is the issue resolved or not?

    wher you have stucked?

     


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Friday, December 23, 2011 11:37 AM
  • i am working on it

    i have created a new relationship for the broker(contact-transaction) and also a new mapping.

    but the field shows the contact name for which i am creating the transaction.

    Anyway thanks to you and phillipe as i have got the idea how to do this....

    May be for some reason I am not getting what exactly I want.

    Regards

    Ayan

    Friday, December 23, 2011 11:59 AM
  • Hi Sandeep / Phillipe

    The problem is not solved till now.

    In the relation "Contact to Transaction" i have a mapping to broker like:

    I can't delete this mapping. But as previously says in the broker field i am getting the contact name for which I am opening the transaction form but not getting the broker name he have in that field.

     

    Thanks

    Ayan

    Tuesday, December 27, 2011 7:26 AM
  • Hi ayan,

    do you need to delete the relation it should not be on form,

    please check on the form and try to remove it.


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Tuesday, December 27, 2011 11:31 AM
  • Hi Sandeep,

    Thanks for your response.

    This relation is autogenerated when i have create the Broker lookup in transaction page.

    Now i have deleted the relationship and have created a new relationship(1:N).

    but the problem is not solved.

    Still i am getting the contact name in the broker name field. when the broker name is different than contact name.

    Tuesday, December 27, 2011 12:24 PM
  • hi ayan,

    i guess you need to write some custom code,to get the data

     


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Tuesday, December 27, 2011 12:27 PM
  • hi ayan,

    is it working for you.

    i have solution for you,

    onload of contract entity write script such way that

     

    if contact name is not null,

    retrieve broker from contact and set to contact_contac_broker.


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by san Sanz Wednesday, December 28, 2011 10:05 AM
    Wednesday, December 28, 2011 10:05 AM
  • Thanks sandeep,

    I have also got this idea from some another blogs but try to solve the Jscript for this purpose.

    can u figure it out the Jscript.

    Actually i am not sure how to do the JS for the

    "retrieve broker from contact and set to contact_contac_broker"

    If you found any solution please let me know.

     

    Thanks again

    Ayan

    Wednesday, December 28, 2011 10:11 AM
  • Hi ayan,

    use this query to get contact id which you selected,

    function callload()
    {
    
    var lookUpObjectValue = Xrm.Page.getAttribute("customerid");
    
    
        if (lookUpObjectValue != null)
      {
             var lookuptextvalue = lookUpObjectValue[0].name;
    
    
             var lookupid = lookUpObjectValue[0].id;
    }
    }

    after you got lookupid,

    use this links to retrieve selected contact value,

    after get the contact .

    get brokerid from contact

    and set using this code

     

    var lookupValue = new Array();
    lookupValue[0] = new Object();
    lookupValue[0].id = brokerid;
    lookupValue[0].name = name;
    lookupValue[0].entityType = entityType;

    Xrm.Page.getAttribute("contact_contac_broker").setValue(lookupValue);


     

     


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Wednesday, December 28, 2011 10:23 AM
  • Thanks sandeep for your quick response.

    let me do with this.

    -------------------------------------------------------

    Thanks

    Ayan

    Wednesday, December 28, 2011 10:40 AM
  • Sandeep i have some questions regarding your post......

    I have create a new web resource for this purpose. In that first i put the callload function. After this function i have the lookupid, its fine.

    Now for the pending work i have see the sdk (JavaScriptRESTDataOperationsSample.js). There are one function:

    function retrieveAccount(AccountId) {

     SDK.REST.retrieveRecord(

         AccountId,

         "Account",

         null,null,

         function (account) {

          writeMessage("Retrieved the account named \"" + account.Name + "\". This account was created on : \"" + account.CreatedOn + "\".");

          updateAccount(AccountId);

         },

         errorHandler

       );

    }

     

    from this function i can get the contact name(as i will change the account -> contact). after this how i will get the broker name related to this contact?

    I have to put all function in one web resource?

    As i am very new in CRM, so this things(may be silly question) are not clear to me.

     

    -----------------------------------------------

    Thanks

    Ayan

    Wednesday, December 28, 2011 10:59 AM
  • ayan,

    whenver you recieved any contact/account from above method,

    it has properties which also contains broker.

    so from there we will get broker.

     function (account) {

          writeMessage("Retrieved the account named \"" + account.Name + "\". This account was created on : \"" + account.CreatedOn + "\".");

    var brokerid=account.brokerId//check in customizations for broker attribute,

    //here you

          //updateAccount(AccountId);

         },


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Wednesday, December 28, 2011 11:42 AM
  • Hi sandeep

    Thanks.

    Now just try to see my scenario:

    1> I have putted the callload function in one web resource.

    2> From this function i have to call the retrive contact function(as in sdk "retrive account"). right?

    So what i will do, copy and paste those function in that web resource and change it accordingly or directly call it from sdk.

    3> This retrive contact  function have a function named retrieveRecord which is there in SDK.Rest.js file.

    how to call this function also?

     

    Thursday, December 29, 2011 4:44 AM
  • Hi ayan,

    please go through sdk,

    location

    "\sdk\samplecode\js\restendpoint\jqueryrestdataoperations\jqueryrestdataoperations\scripts"

    you will have the js , you can import the managed solution and try how it is working,

    then modify it for your purpose.


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Thursday, December 29, 2011 5:16 AM
  • This problem is solved, Thanks sandeep but the code provided by you is not required in my case. I am giving the exact Jscript code what i have done and now it is running successfully.

     

    function AlertText() { 

    var primaryContactName = Xrm.Page.data.entity.attributes.get("new_contactname").getValue()[0].name; 

    var primaryContactID = Xrm.Page.data.entity.attributes.get("new_contactname").getValue()[0].id; 

    var brokernameTEMP = RetrieveEntityById("contact", primaryContactID, "new_broker");

    var brokername = RetrieveEntityById("contact", brokernameTEMP, "fullname");

    Xrm.Page.data.entity.attributes.get("new_brokername").setValue(brokername);

    }

     

     

     

    function RetrieveEntityById(EmployeeEntityName, EmployeeId, NameFieldAttributeName) {

     

        var resultXml;

        var AttributeVal = null;

        var errorCount;

        var msg;

        var xmlHttpRequest;

        var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();

     

        //Prepare the SOAP message.

        var xml = "<?xml version='1.0' encoding='utf-8'?>" +

       "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +

       " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +

       " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +

       authenticationHeader +

       "<soap:Body>" +

       "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +

       "<entityName>" + EmployeeEntityName + "</entityName>" +

       "<id>" + EmployeeId + "</id>" +

       "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +

       "<q1:Attributes>" +

     

      "<q1:Attribute>" + NameFieldAttributeName + "</q1:Attribute>" +

       "</q1:Attributes>" +

       "</columnSet>" +

       "</Retrieve></soap:Body></soap:Envelope>";

     

        //call function to create Soap Request to ms crm webservice

        xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

        xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);

        xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");

        xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

        xmlHttpRequest.setRequestHeader("Content-Length", xml.length);

        xmlHttpRequest.send(xml);

     

        resultXml = xmlHttpRequest.responseXML;

     

        var errorCount = resultXml.selectNodes('//error').length;

     

        if (errorCount != 0) {

            var msg = resultXml.selectSingleNode('//description').nodeTypedValue; //Process and display the results.

            alert("Error occured: " + msg);

        }

        else {

            if (resultXml.selectSingleNode('//q1:' + NameFieldAttributeName) != null) {

                AttributeVal = resultXml.selectSingleNode('//q1:' + NameFieldAttributeName).nodeTypedValue;

            }

        }

        return AttributeVal;

    }

     

     

    Regards,

    Ayan Choudhury

    ------------------------------------------------------------------

    If you found this as helpful please Vote as Helpful

    • Marked as answer by aanch Friday, December 30, 2011 7:09 AM
    Friday, December 30, 2011 7:09 AM