locked
Get all the case id's of an account from webservices RRS feed

  • Question

  • how can i get all the case id's of an account from web services

    i want to retrieve some data of each case associated with that account

    Friday, February 5, 2010 10:58 AM

Answers

  • Hi,
    First, put your attributes here, for which you are reteriving data.

    cols.Attributes = new string [] {"name", "cas_atttribute"};

    e.g.
    cols.Attriubtes = new string[]{"incidentid"};

    secondly, soory for that, customerid is of type customer, so try this.

    Lookup prop = new Lookup ();
    prop.Value = new Guid("type your id here");
    prop.type  = EntityName.account.ToString();

    query.Values = new object[]{prop};
    Friday, February 5, 2010 11:30 AM

All replies

  • Hi,

    You easily fetch this using JS,
    I will suggest you to download FetchXML query builder (You can design query there).

    http://jamesdowney.net/blog/page/Request-FetchXML-Builder-Key.aspx

     


    Mahain
    Friday, February 5, 2010 11:03 AM
    Moderator
  • USE queryByAttribute.

    Example

    The following code example shows how to use the QueryByAttribute class.

    [C#]
    // Set up the CRM Service.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    token.AuthenticationType = 0; 
    token.OrganizationName = "AdventureWorksCycle";
     
    CrmService service = new CrmService();
    service.Url = ""http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
    service.CrmAuthenticationTokenValue = token;
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;
    
    // Create a column set holding the names of the columns to be retrieved.
    ColumnSet cols = new ColumnSet();
    cols.Attributes = new string [] {"name", "cas_atttribute"};
    
    // Create the query object.
    QueryByAttribute query = new QueryByAttribute();
    query.ColumnSet = cols;
    query.EntityName = EntityName.incident.ToString();
    
    // The query will retrieve all accounts whose address1_city is Sammamish.
    query.Attributes = new string [] {"customerid"};
    query.Values = new Guid[] {"Account ID Here"};
    
    // Execute the retrieval.
    BusinessEntityCollection retrieved = service.RetrieveMultiple(query);
    Friday, February 5, 2010 11:04 AM
  • i want to get all the guid of the cases of that account
    Friday, February 5, 2010 11:06 AM
  • this is giving error

    cannot implicitly convert string to guid

    if i pass guid it says cannot implicitly convert string[] to object[]
    Friday, February 5, 2010 11:15 AM

  • query.Attributes = new string [] {"customerid"};

    Guid accountId = new Guid("type your id here");

    query.Values = new object[]{accountId};
    Friday, February 5, 2010 11:17 AM
  • Server was unable to process request.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.Services.Protocols.SoapException: Server was unable to process request.

    Source Error:

    Line 341:        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple", RequestNamespace="http://schemas.microsoft.com/crm/2007/WebServices", ResponseNamespace="http://schemas.microsoft.com/crm/2007/WebServices", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    Line 342:        public BusinessEntityCollection RetrieveMultiple(QueryBase query) {
    Line 343:            object[] results = this.Invoke("RetrieveMultiple", new object[] {
    Line 344:                        query});
    Line 345:            return ((BusinessEntityCollection)(results[0]));

    Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\patient\834d7e21\258e5824\App_WebReferences.a4rj2wth.0.cs    Line: 343

    Stack Trace:

    [SoapException: Server was unable to process request.]
       System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +431766
       System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +204
       crmsdk.crmservice.CrmService.RetrieveMultiple(QueryBase query) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\patient\834d7e21\258e5824\App_WebReferences.a4rj2wth.0.cs:343
       Patient_pastRX.Page_Load(Object sender, EventArgs e) in d:\emr\patient\Patient_pastRX.aspx.cs:40
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +50
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
    
    Friday, February 5, 2010 11:21 AM
  • I have just modefied code from Muhammahd  to get caseId and Case Title now..see below...


    QueryExpression query = new QueryExpression();
    
    query.EntityName="incident";
    
    ColumnSet columns = new ColumnSet();
    columns.Attributes = new string[] { "incidentid","title" };
    query.ColumnSet = columns;
    
    
    query.Criteria = new FilterExpression();
    query.Criteria.FilterOperator = LogicalOperator.And;
    
    
    ConditionExpression condition1 = new ConditionExpression();
    condition1.AttributeName = "customerid";
    condition1.Operator = ConditionOperator.Equal;
    condition1.Values = new object[] { <<accountID>> };
    
    
    query.Criteria.Conditions = new ConditionExpression[] { condition1 };
    






    BusinessEntityCollection retrieved = service.RetrieveMultiple(query);

    Friday, February 5, 2010 11:24 AM
  • Hi,
    First, put your attributes here, for which you are reteriving data.

    cols.Attributes = new string [] {"name", "cas_atttribute"};

    e.g.
    cols.Attriubtes = new string[]{"incidentid"};

    secondly, soory for that, customerid is of type customer, so try this.

    Lookup prop = new Lookup ();
    prop.Value = new Guid("type your id here");
    prop.type  = EntityName.account.ToString();

    query.Values = new object[]{prop};
    Friday, February 5, 2010 11:30 AM