Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Retrieve related data field via CRM lookup field

Posted on 2012-03-15
3
Medium Priority
?
1,404 Views
Last Modified: 2012-03-29
Hello Experts,

Environment:  Microsoft Dynamics CRM 4.0
Entity:  Contracts

When opening an existing Contract, I want to display in an ALERT, the state where the Customer is located.  So, I open a existing Contract and bam, "FL" shows up in an ALERT statement for Clients where the CustomerId lookup field's corresponding Account record has "FL" for the value in the "address1_stateorprovince" field.  

What's the best way to do this?  I've been able to successfully alert the CustomerID, Name, & Typename as shown in the link below, under the lookup value section for example #1.

http://sites.google.com/site/ranjitclub/working-with-datatypes-in-javascript
0
Comment
Question by:2_under_par
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
Feridun Kadir earned 2000 total points
ID: 37726046
To get the address1_stateorprovince field you will need to call the CRM webservices to retrieve the record for the customer.

In the contract form you can use JavaScript (as you have found) to alert the contents of any field that is shown on the form. However, the state is not on the form but is in the record for the customer.

The CRM 4.0 SDK has some information "Accessing Microsoft Dynamics CRM Web Services".
0
 
LVL 30

Assisted Solution

by:Feridun Kadir
Feridun Kadir earned 2000 total points
ID: 37726054
This article may help you get started: http://go4answers.webhost4life.com/Example/access-lookup-fields-data-javascript-117618.aspx

You'll need to amend to suit your instance; the structure is as follows:

an authentication section
a query that specifies the columns to return (in your case just the state)
construct and send the request to the web services
processing the result
0
 

Author Closing Comment

by:2_under_par
ID: 37784419
Thanks!  I got busy and forgot to follow up with this thread.  There is a little bit extra posted below, in that I retrieved more fields than I needed, but this got it done.  Var named 'Mess' displays in an alert.

if(crmForm.FormType == 4 ) 
 {    // Create Form = 1

var Mess ='';
  var AccountLookUp = crmForm.all.customerid.DataValue;
 var authenticationHeader = window.opener.GenerateAuthenticationHeader();

if (AccountLookUp != null && AccountLookUp != "undefined")
{
// Get the value for the accountid from the array and set it to a variable
var AccountID = AccountLookUp [0].id;
var Name=AccountLookUp [0].name;

var Accountxml =  [  
        "<?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>",  
        "   <RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>",  
       "<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:QueryByAttribute\'>",
// Query the customeraddress entity.
 "<q1:EntityName>account</q1:EntityName>",
 // Set the columns you want to return.
"<q1:ColumnSet xsi:type='q1:ColumnSet'>",
 "<q1:Attributes>",
 "<q1:Attribute>address1_name</q1:Attribute>",
 "<q1:Attribute>address1_line1</q1:Attribute>",
"<q1:Attribute>address1_line2</q1:Attribute>",
 "<q1:Attribute>address1_line3</q1:Attribute>",
"<q1:Attribute>address1_city</q1:Attribute>",
 "<q1:Attribute>address1_stateorprovince</q1:Attribute>",
"<q1:Attribute>address1_postalcode</q1:Attribute>",
 "<q1:Attribute>address1_country</q1:Attribute>",
"<q1:Attribute>address1_telephone1</q1:Attribute>",
"<q1:Attribute>address1_addresstypecode</q1:Attribute>",
 "<q1:Attribute>address1_shippingmethodcode</q1:Attribute>",
"<q1:Attribute>address1_freighttermscode</q1:Attribute>",
 "<q1:Attribute>telephone1</q1:Attribute>",
 "</q1:Attributes>",
 "</q1:ColumnSet>", 
 // Specify the attribute that you are querying on.
 "<q1:Attributes>", 
 "<q1:Attribute>name</q1:Attribute>",
 "</q1:Attributes>", 
 // Set the value of the attribute using the customerid 
 // value of the case record.
 "<q1:Values>",
 "<q1:Value xsi:type='xsd:string'>",
Name ,
 "</q1:Value>",
 "</q1:Values>",
 "</query>" , 
"   </RetrieveMultiple>",  
        "</soap:Body>",  
        "</soap:Envelope>" 
        ].join("");  

// Create an instance of an XMLHTTP object.
 var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
// Configure the XMLHttp object for the 
// Microsoft CRM Web services.
 xmlHttpRequest.Open(
  "POST", 
  "/mscrmservices/2007/CrmService.asmx", 
  false
  );
 xmlHttpRequest.setRequestHeader(
  "SOAPAction",
  "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple"
  );
 xmlHttpRequest.setRequestHeader(
  "Content-Type", "text/xml; charset=utf-8"
  );
 xmlHttpRequest.setRequestHeader(
  "Content-Length", Accountxml .length
  );
// Send the XMLHttp request.
 xmlHttpRequest.send(Accountxml );
// Capture the XMLHttp response in XML format.
 var resultAccountxml  = xmlHttpRequest.responseXML;

// Create an XML document that you can parse.
 var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
 oXmlDoc.async = false; 
// Load the document that has the results.
 oXmlDoc.loadXML(resultAccountxml.xml);
 // Get only the BusinessEntity results.

 var businessEntities = oXmlDoc.getElementsByTagName('BusinessEntity');

  var errorCount = resultAccountxml.selectNodes('//error').length; 
    if (errorCount != 0) 
    { 
     var msg = resultAccountxml.selectSingleNode('//description').nodeTypedValue; 
     alert(msg); 
    }  


for (i=0;i < businessEntities.length;i++)
 {
if (businessEntities[i].selectSingleNode('./q1:address1_name') != null)
{
var name =businessEntities[i].selectSingleNode('./q1:address1_name').nodeTypedValue;
crmForm.all.address1_name.DataValue=name;
}

if(businessEntities[i].selectSingleNode('./q1:address1_stateorprovince')!=null)
{
var Mess =businessEntities[i].selectSingleNode('./q1:address1_stateorprovince').nodeTypedValue;
alert(Mess);
}



}
}
}

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: You must have administrative privileges in order to create/edit Sharing Rules. Salesforce.com (http://www.salesforce.com) (SFDC) is a cloud-based customer relationship management (CRM) system. It is a database most commonly used by sales an…
In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question