locked
Creating a case from contact which autopopulates the contact name in customer contact RRS feed

  • Question

  • Hello,

    I was wondering if this is possible. Currently, if I go and click Sales -> Contacts -> Search for Contact -> click on the contact -> contact information form opens -> on the left nav I click Cases which opens another window to display cases for contact -> Now I click New Case which opens the case:New window with the contact name autopopulated in the field.

    Is there a way to autopopulate the accountname from the contact at the same time when the Case:New form opens?

    I currently have a script that I use for customer contact that onchange (when you click and pick the contact it autopopulates the company name on the form. The problem I am having is autopopulating when the form opens when creating the case from contact.

    //Script I am using for onchange method for customer contact.

    if(crmForm.all.customerid.DataValue != null)
    {
    var parentCustomerID = document.getElementById( "customerid" );
    var lookupItems = parentCustomerID.items[0].values;

    crmForm.mcaslt_companyname.DataValue = lookupItems[1].value ;
    }

    Any thoughts?


    Jose Fleitas
    Friday, November 4, 2011 9:20 PM

Answers

All replies

  • Hi Jose ,

     You can use Query using fetch XML to get any attritube values of any related entity.

     Eg : This example demostrate query to get the State of a CASE called from any other related entity

    function GetCurrentCaseState(caseId) {
        var retVal = "";

        var sFetchXmlQuery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='incident'><attribute name='statecode' /> <filter> <condition attribute='incidentid' operator='eq' value='" + caseId + "' /> </filter></entity> </fetch>";

        var fetchXmlResult = Fetch(sFetchXmlQuery);
        if (fetchXmlResult != null) {
            errorCount = fetchXmlResult.selectNodes('//error').length;
            if (errorCount == 0) {
                var regardingObject = fetchXmlResult.selectSingleNode("//statecode");
                if (regardingObject != null) {
                    retVal = regardingObject.text;
                }
            }
        }
        return retVal;
    }

    // Fetch Function
    function Fetch(xml) {
        var Xml = "<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\">"
        Xml += GenerateAuthenticationHeader()
        Xml += "<soap:Body>";
        Xml += "<Fetch xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">";
        Xml += "<fetchXml>";
        Xml += FetchEncode(xml); // Microsoft _HtmlEncode function
        Xml += "</fetchXml>";
        Xml += "</Fetch>";
        Xml += "</soap:Body>";
        Xml += "</soap:Envelope>";

        var XmlHttp = CreateXmlHttpObject(); // Microsot CreateXmlHttp function
        XmlHttp.open("POST", "/mscrmservices/2007/crmservice.asmx", false); //Sync Request
        XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        XmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
        XmlHttp.send(Xml);
        var XmlDoc = new ActiveXObject("Msxml2.DOMDocument");
        XmlDoc.async = false;
        XmlDoc.resolveExternals = false;
        XmlDoc.loadXML(XmlHttp.responseXML.text);

        return XmlDoc;
    }

    This Fetch XML can be formed either using Advance find or using a tool such as one in stuntware site.

    http://www.stunnware.com/crm2/

     

    Hope this helps

    Dk

    --------------------------------------------------------------------------------
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".

     

    • Proposed as answer by D kay Friday, November 4, 2011 10:01 PM
    Friday, November 4, 2011 10:00 PM
  • I think case entity has an attribute for customerid that accepts both account and contact. In addition to that it also as another attribute to accept Responsible Contact which is a lookup to contact.

    The autopopulate of contact on Case happens because of the relationship mapping set for contact and case. You can edit the contact entity modify the mappings of the case-contact relationship, set the contact to map to responsible contact and contact.parentcustomer to case.customerid.

    This way it will auto populate both the account and contact lookup and there may not be a need for the script or you can move your same script to onload event as these will be autopopulated on form load.

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Saturday, November 5, 2011 2:25 AM
    Saturday, November 5, 2011 2:25 AM
  • Hi Jose

    Did this help?

    Please make sure to mark as answer to the response that helped you get through. This will

    help others with similar problem identify the answer and also close this thread as resolved.

    Thanks

    Dk

    Monday, November 7, 2011 1:40 AM
  • Hello Sam,

    I am currently using a nvarchar type for companyname. I can't map a lookup type with nvarchar type. Is there a way to map these two entities? I am currently using these attributes on the case form. I am using a customerid lookup for Customer Contact and Company Name (nvarchar type) that should populate Account name. What do you think?

     

    Jose

     

     

     


    Jose Fleitas
    Monday, November 7, 2011 2:48 PM
  • Hello DK,

    I am currently looking at your script. The attributes I am using on the form are Customer Customerid lookup and CompanyName (nvarchar type) that should populate Account name.

    Jose


    Jose Fleitas
    Monday, November 7, 2011 2:51 PM
  • Sam,

    I was able to use the mapping as you recomended, and it did work; but I am using a nvarchar type for company name so I cant map customerid Lookup with nvarchar companyname attribute.

     

    Jose


    Jose Fleitas
    Monday, November 7, 2011 4:52 PM
  • Hello,

    I found a good link: http://smebusinesssoftware.blogspot.com/2011/02/jscript-code-in-dynamics-crm-to-show.html
    that will help autopopulate accountname when picking the contact from customerid. This fetch really did the trick. I implemented it on the onload for the case form and onchange for customerid lookup.

    Thanks everyone for your help!


    Jose Fleitas
    • Marked as answer by JoseFleitas Wednesday, November 9, 2011 8:15 PM
    Wednesday, November 9, 2011 8:14 PM