CRMQuery.CreateAndRetrieve Method
The CreateAndRetrieve method creates a new query and then retrieves it.
Syntax
[Visual Basic .NET]
Public Function CreateAndRetrieve(
ByVal Caller As CUserAuth,
ByVal objectType As ObjectType,
ByVal QueryXML As String
) As String
[C#]
public string CreateAndRetrieve(
CUserAuth Caller,
ObjectType objectType,
string QueryXML
);
[C++]
public: String* CreateAndRetrieve(
CUserAuth* Caller,
ObjectType objectType,
String* QueryXML
);
Parameters
Caller
Specifies the identity of the caller. To perform this action, the caller must have the prvCreateQuery and prvReadQuery privileges. See CUserAuth.
ObjectType
Specifies the type of object to be queried. See CObjectName.
QueryXML
Specifies an XML string representing the query. The XML schema is described by savedquery.xsd.
Return Value
Returns a String type that specifies the XML data representing the new query. The XML schema is described by savedquery.xsd.
Remarks
If there is an error, SOAP throws an exception and the error message is reported in System.Web.Services.Protocols.SoapException.Detail.OuterXml.
All IDs passed to the platform are GUIDs wrapped in braces. For example: {6522D89A-A752-4455-A2B0-51494C6957C3}
Example
[C#]
// strServer should be set with the name of the platform Web server
string strServer = "mystrServername";
// virtualDirectory should be set with the name of the Microsoft CRM
// virtual directory on the platform Web server
string virtualDirectory = "mscrmservices";
string strDir = "https://" + strServer + "/" + virtualDirectory + "/";
// BizUser proxy object
Microsoft.Crm.Platform.Proxy.BizUser bizUser = new Microsoft.Crm.Platform.Proxy.BizUser ();
bizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
bizUser.Url = strDir + "BizUser.srf";
// CRMQuery proxy object
Microsoft.Crm.Platform.Proxy.CRMQuery query = new Microsoft.Crm.Platform.Proxy.CRMQuery();
query.Credentials = System.Net.CredentialCache.DefaultCredentials;
query.Url = strDir + "CRMQuery.srf";
string strErrorMsg;
string strQueryXml;
try
{
Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = bizUser.WhoAmI();
// Set up the XML string for the query
strQueryXml = "<savedquery>";
strQueryXml += "<description>Account query</description>";
strQueryXml += "<name>Account Query 3</name>";
strQueryXml += "<isquickfindquery>1</isquickfindquery>";
strQueryXml += "<iscustomizable>1</iscustomizable>";
strQueryXml += "<returnedtypecode>1</returnedtypecode>";
strQueryXml += "<isdefault>1</isdefault>";
strQueryXml += "<querytype>" + Microsoft.Crm.Platform.Types.SAVED_QUERY_TYPE.ADVANCED_SEARCH.ToString() + "</querytype>";
strQueryXml += "</savedquery>";
// Create the query, and the retrieve it
string strResultsXml = query.CreateAndRetrieve(userAuth, Microsoft.Crm.Platform.Proxy.ObjectType.otAccount, strQueryXml);
}
catch (System.Web.Services.Protocols.SoapException err)
{
// Process the platform error here
strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml + " Source: " + err.Source );
}
catch (Exception err)
{
// Process other errors here
strErrorMsg = ("ErrorMessage: " + err.Message );
}
Requirements
Namespace: Microsoft.Crm.Platform.Proxy
Assembly: Microsoft.Crm.Platform.Proxy.dll
See Also