locked
CRM 2011 Online | Know the state of Quote with C# RRS feed

  • Question

  • Hi to everybody,

    I wanto to know the state of a Quote i've retrieved.

    I see that i need to check the statusCode field (thats is a QuoteState object) and try a stateRequest, i've used SetStateRequest but i haven't found a GetStateRequest

    CRM 2011 Online, Visdual Studio 2010

    connectionString = "Url=" + urlCrm + "; Username=" + username + "; Password=" + psw + "; DeviceID=11hfn41bbqrg580vyvoea05abc; DevicePassword=fuqNIlx%e$.l*+ax_#8O4abc;";

                try
                {
                    Microsoft.Xrm.Client.CrmConnection connection = CrmConnection.Parse(connectionString);

                    using (_orgService = new OrganizationService(connection))
                    {
                        QueryExpression query = new QueryExpression();
                        query.EntityName = Quote.EntityLogicalName;
                        query.ColumnSet = new ColumnSet();
                        query.Criteria.AddCondition(new ConditionExpression("new_CustomCondition", ConditionOperator.Equal, idProg));

                        EntityCollection ec = _orgService.RetrieveMultiple(query);


                        if (ec.Entities.Count == 1)
                        {

                              TODO: CHECK TEH STATE OF THE QUOTE

                        }

                   }


    Every help will be appreciate

    Monday, January 7, 2013 11:07 AM

Answers

All replies

  • Have you tried

    if(ec.Entities[0].Contains("statuscode")) {

    OptionSetValue status = (OptionSetValue)ec.Entities[0]["statuscode"];

    }

    http://msdn.microsoft.com/en-us/library/gg594435.aspx


    MS CRM Bing'd - http://bingsoft.wordpress.com
    Dynamics XRM Tools CRM 4 to CRM 2011 JavaScript Converter Tool
    CRM 2011 OData Query Designer
    CRM 2011 Metadata Browser
    CRM Forum Guidance

    • Proposed as answer by Amreek Singh Monday, January 7, 2013 12:21 PM
    Monday, January 7, 2013 11:33 AM
    Moderator
  • Adding to Rhet's answer there is getStateRequest.

    You can get the state from statecode and statuscode.  for every statecode there can be one or more status code

    For example here is list of statecode and statuscodes

    statecode statuscode

    draft inprogress

    active inprogress, open

    won won

    closed lost, cancelled, revised

    Few line about the code

    OptionSetValue status = (OptionSetValue)ec.Entities[0]["statuscode"]; // this line will return an optionset

    //to get the value you can use something like

    int statusValue= status.Value; // this will return an integer.

    // if you want get the text description of the status you can use the formatedvalue. something like

     string statusText = ec.Entities[0].FormattedValues["statuscode"]; //this return the text value like inprogress, won and lost etc.

    I hope this helps.



    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior Solution Architect HP Australia Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com

    • Proposed as answer by Amreek Singh Monday, January 7, 2013 12:21 PM
    Monday, January 7, 2013 12:21 PM
  • @ RhettClinton

    Thanks for your help.

    Your code works but mine quote doesn't contains anything (the condition result false). It' s strange because from the web page of CRM Online i see that's it's won.

    Previously i've checked the state of the Quote using "QuoteState? qs = currQuote.stateCode" but that's gave me an error (Object null - and infact seem it don't contains anything)

    @ Amreek Singh

    Thanks for your help.

    Your code doesn't work here and give me an exception (KeyNotFoundException)

    OptionSetValue status = (OptionSetValue)ec.Entities[0]["statuscode"];

    I was thinking to use something like getStateRequest but it's an unknow key word

    What doyou think?


    Monday, January 7, 2013 4:29 PM
  • Is it because you are not saying which columns to retrieve here

    query.ColumnSet = new ColumnSet();

    try

    query.ColumnSet = new ColumnSet(new string[]{"statuscode"});


    MS CRM Bing'd - http://bingsoft.wordpress.com
    Dynamics XRM Tools CRM 4 to CRM 2011 JavaScript Converter Tool
    CRM 2011 OData Query Designer
    CRM 2011 Metadata Browser
    CRM Forum Guidance



    Monday, January 7, 2013 4:33 PM
    Moderator
  • same problem with my example

    query.ColumnSet  = new ColumnSet("statecode", "statuscode", "customerid") // add any other attribute you want.

    or try the following line to retrieve all the columns

    query.ColumnSet .ColumnSet = new ColumnSet(true);

    also check if the attribute exist using the line posted by Rhet

    if (ec.Entities[0].Contains("statuscode")) // change the attribute name as required.

    I hope this helps.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior Solution Architect HP Australia Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com


    Monday, January 7, 2013 10:33 PM
  • It worked, thank you!

    It's what you say: i used query.ColumnSet = new ColumnSet(new string[]{"statuscode"}); and i get the statusCode and then checked the status.

    By the way another, simple, question: using query.ColumnSet = new ColumnSet() I get the id for each record? I think so because whene i made update, the relative record was modified.

    Thnak you also to Amreek Singh.

    Bye

    Wednesday, January 16, 2013 9:51 AM