locked
How to get all sales orders or get sales orders by accounts - CRM online Webservices API RRS feed

  • Question

  • Hi All,
        I'm a newbie in CRM online development.

    I would like to list all orders via web services.

    But i keep getting error : SalesOrders is not in the metacache.

    Code snippet below:

     QueryExpression query = new QueryExpression
                        {
                            EntityName = "SalesOrder",
    
                            //EntityName =  new EntityReference(Entity, new Guid(""))
                            ColumnSet = new ColumnSet("name")
    
    
                        };
                       
                        EntityCollection ec = service.RetrieveMultiple(query);
    
                       
                        Response.Write("Retrieved " + ec.Entities.Count.ToString() + "Orders<br/><br/>");
    
                        foreach (Entity act in ec.Entities)
                        {
                            Response.Write("" + act["name"] + "<br/>");
                        }
                        
                      

    Thanks in advance






    • Edited by Patrick.I Wednesday, November 7, 2012 6:58 AM
    Wednesday, November 7, 2012 4:02 AM

Answers

  • Hi,

    just replace this line:

    sales.Attributes["accountid"] = "7add2ae4-5423-e211-aec7-1cc1de6daa0b";

    with this one:

    salesOrder.Attributes["customerid"] = new EntityReference("account", new Guid("7add2ae4-5423-e211-aec7-1cc1de6daa0b"));

    Greetings,

    Pavlos



    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.

    • Proposed as answer by Pavlos Panagiotidis Tuesday, November 13, 2012 7:50 AM
    • Marked as answer by Patrick.I Tuesday, November 13, 2012 11:37 AM
    Tuesday, November 13, 2012 7:49 AM
  • Hi,

    try using "salesorder" instead of "SalesOrder" (lower case).

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.

    • Proposed as answer by Pavlos Panagiotidis Wednesday, November 7, 2012 7:30 AM
    • Marked as answer by Patrick.I Thursday, November 8, 2012 8:22 PM
    Wednesday, November 7, 2012 7:30 AM

All replies

  • Hi,

    try using "salesorder" instead of "SalesOrder" (lower case).

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.

    • Proposed as answer by Pavlos Panagiotidis Wednesday, November 7, 2012 7:30 AM
    • Marked as answer by Patrick.I Thursday, November 8, 2012 8:22 PM
    Wednesday, November 7, 2012 7:30 AM
  • Thanks i did figure that out eventually :)

    But one question though if i need to create orders via web services do i need to supply a customer id apart from a customer name?

    If that's true whats the field column name for customerid as when i use it it keeps telling me its not available.

    Cheers and thanks in advance.

    Thursday, November 8, 2012 8:22 PM
  • Hi,

    try using "accountid" or "contactid" instead, depending on if the customer is an account or a contact. Also have a look at this to see all the SalesOrder attribute metadata.

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.

    Friday, November 9, 2012 5:57 AM
  • Hi Pavlos,
            Thank you very much for the response.

    But anytime i try to get the "accountid" i get error:

    "The given key was not present in the dictionary."

    If you have created orders via the API web services what are the required attributes yo supplied?

    Any ideas?

    Cheers in advance





    • Edited by Patrick.I Monday, November 12, 2012 7:22 AM
    Monday, November 12, 2012 7:11 AM
  • Hi,

    you don't need to add the "accountid" attribute to the columnset. You can get the Id simply by using the Id Property of the "Entity" class, as below:

     QueryExpression query = new QueryExpression
                        {
                            EntityName = "account",
                            ColumnSet = new ColumnSet("name", "new_websiteuserid")
                           
                        };
                        EntityCollection ec = service.RetrieveMultiple(query);
    
                     
                   
                        foreach (Entity act in ec.Entities)
                        {
                            Response.Write("Acct Name: " + act["name"] + "- User ID: " + act["new_userid"] + "<br/>" + act.Id);
                        }

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.

    Monday, November 12, 2012 7:19 AM
  • Hi Pavlos,
             Thanks for that i didn't know i can get the id and the Entity.LogicalName.

    Regarding my last post i did ask how i can create order. 

    I have hardcoded some attributes as yo can see below. I did add the accountid as i wanted to order for that account.

    Not sure if this is the right way.I don't think so:(

    But when i run this code i get error: Customer name is not sepcified

    The

    new_orderid is a custom column

      serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
                        IOrganizationService service = (IOrganizationService)serviceProxy;
                        //Define Entity Object
                        Entity sales = new Entity("salesorder");
                        //Specify the attributes
                        //cname = "Customer Name";
                        sales.Attributes["name"] = cname;
                        sales.Attributes["pricelevelid"] = "176ED1F8-6710-E211-AEC7-1CC1DE6DAA0B";
                        sales.Attributes["transactioncurrencyid"] = "F67567BF-370D-E211-A840-1CC1DE6DAA3E";
                        sales.Attributes["new_orderid"] = 14;
                        sales.Attributes["accountid"] = "7add2ae4-5423-e211-aec7-1cc1de6daa0b";
              
    
                        //Execute the service
                        salesId = service.Create(sales);
                        //Confirmation Message
                        
                        message = "Order Created with Name:- " + cname + " Guid is" + salesId.ToString();
                        //Response.Write(message);
    Thanks a lot.


    • Edited by Patrick.I Tuesday, November 13, 2012 7:44 AM
    Tuesday, November 13, 2012 12:54 AM
  • Hi,

    just replace this line:

    sales.Attributes["accountid"] = "7add2ae4-5423-e211-aec7-1cc1de6daa0b";

    with this one:

    salesOrder.Attributes["customerid"] = new EntityReference("account", new Guid("7add2ae4-5423-e211-aec7-1cc1de6daa0b"));

    Greetings,

    Pavlos



    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.

    • Proposed as answer by Pavlos Panagiotidis Tuesday, November 13, 2012 7:50 AM
    • Marked as answer by Patrick.I Tuesday, November 13, 2012 11:37 AM
    Tuesday, November 13, 2012 7:49 AM