- Link-Entity and SDK
- Posted by Kristina Ledford on November 4th, 2003
I am trying to return results from Account and Contact using the SDK and
Link-Entity. I get the following error:
ErrorMessage: SOAP Server Application Faulted c00ce509Application Error
Source: System.Web.Services
Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.CRM.Proxy;
using System.Xml;
using System.Text.RegularExpressions;
namespace CRM_BlastFax
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblResults;
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
// strServer should be set with the name of the platform Web server
string strServer = "IASCRM1";
// strVirtualDirectory should be set with the name of the Microsoft CRM
// virtual directory on the platform Web server
string strVirtualDirectory = "mscrmservices";
string strDir = "http://" + strServer + "/" + strVirtualDirectory + "/";
// BizUser proxy object
Microsoft.CRM.Proxy.BizUser oBizUser = new Microsoft.CRM.Proxy.BizUser ();
oBizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
oBizUser.Url = strDir + "BizUser.srf";
// Query proxy object
Microsoft.CRM.Proxy.CRMQuery oQuery = new Microsoft.CRM.Proxy.CRMQuery ();
oQuery.Credentials = System.Net.CredentialCache.DefaultCredentials;
oQuery.Url = strDir + "CRMQuery.srf";
string strErrorMsg;
string strAccounts;
try
{
Microsoft.CRM.Proxy.CUserAuth oUserAuth = oBizUser.WhoAmI();
// This is "select * from Account" and will return
// all accounts for which you have read access
string strQuery = "<fetch mapping='logical'><entity name='account'>";
strQuery += "<attribute name = 'name'/>";
strQuery += "<attribute name = 'accountnumber'/>";
strQuery += "<link-entity name='contact' to='contactid'>";
strQuery += "</link-entity>";
strQuery += "<filter type='and'>";
strQuery += "<condition attribute = 'CFIMarketing_Code'";
strQuery += "operator='eq' value='6'/>";
strQuery += "</filter>";
strQuery += "</entity></fetch>";
// This should return a resultset with all the accounts you can see
strAccounts = oQuery.ExecuteQuery(oUserAuth, strQuery);
lblResults.Text = strAccounts.ToString();
}
catch(System.Web.Services.Protocols.SoapException err)
{
// Process the platform error here
strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml +
" Source: " + err.Source );
lblResults.Text = strErrorMsg.ToString();
}
catch(Exception err)
{
// Process other errors here
strErrorMsg = ("ErrorMessage: " + err.Message + "Source: " + err.Source );
lblResults.Text = strErrorMsg.ToString();
}
}
}
}
- Posted by Kristina Ledford on November 4th, 2003
Make that this error (I had a typo in the last run)
ErrorMessage: SOAP Server Application Faulted 80040216An unexpected error
occurred.The attribute 'contactid' is not present on the entity
'Account'.d:\mscrm\build\3017\src\platform\include \omcore\qb\queryplan.inl14
66 Source: System.Web.Services
I used the example found both in the SDK on in the TK..... ??
- Posted by Kristina Ledford on November 4th, 2003
Basically - I want to pull back attributes from both tables, account and
contact...
I now have them joining up - but when I list an attribute that is in the
contact table - it tells me its not in the table account.... so how to I
tell it to pull from both?
string strQuery = "<fetch mapping='logical'><entity name='account'>";
strQuery += "<attribute name = 'name'/>";
strQuery += "<attribute name = 'accountnumber'/>";
strQuery += "<attribute name = 'firstname'/>";
strQuery += "<attribute name = 'lastname'/>";
strQuery += "<attribute name = 'salutation'/>";
strQuery += "<filter type='and'>";
strQuery += "<condition attribute = 'CFIMarketing_Code' ";
strQuery += "operator='eq' value='6'/>";
strQuery += "</filter>";
strQuery += "<link-entity name='contact' to='primarycontactid'
link-type='Outer'>";
strQuery += "</link-entity>";
strQuery += "</entity></fetch>";