locked
Multiple Quote cancellation in MSCRM RRS feed

  • Question

  • Hi All, I have a scenario which need to be implemented. I am stuck with that. THere are multiple Quotes in my Organisation. I want to select multiple entries and cancel it. for that i kept a cancel button in the menu bar. WHen i select multiple quotes and click cancel, it should change the status of the quote to cancel. For that i am calling an aspx page where it will be done using javascript. After getting the GUID's , i need to pass that data using XML to other system. i tried doing refering to this article but couldnt do it : http://msdn.microsoft.com/en-us/library/cc150860.aspx Can you please suggest how can i acheive this? Thanks in Advance Sini
    sini_tg
    Wednesday, February 24, 2010 12:44 PM

Answers

  • Hi Sini.
    1) To get the selected rows, use this code.
    var a = document.all['crmGrid'].InnerGrid.SelectedRecords;
    var selectedItems = new Array(a.length);
    for (var i=0; i < a.length; i++)
    {
        selectedItems[i] = a[i][0];
    }
    alert(selectedItems);
    http://blog.customereffective.com/blog/2009/08/fun-with-the-crm-grid-object.html

    2) To convert the "Quote" status, use this message "SetStatusQuote".
    http://msdn.microsoft.com/en-us/library/bb959551.aspx
    and specify
    // Create the request object.
    SetStateQuoteRequest state = new SetStateQuoteRequest ();

    // Set the properties of the request object.
    state.QuoteState = AccountState.Closed;
    state.QuoteStatus = 5; // 5 means lost


    // EntityId is the GUID of the account whose state is being changed.
    state.EntityId = new Guid("AD618DB2-F0DB-4A6A-8C4B-2F2213EAA38E");;

    // Execute the request.
    SetStateQuoteResponse stateSet = (SetStateQuoteResponse )service.Execute(state);


    3)  Convert the above code in to javascript using the below.
    http://www.stunnware.com/crm2/topic.aspx?id=jswebservice2

    4) put the above code in the javascript="your javascript code here", in the ISV.config button.
    That's all :)



    Muhammad Ali Khan
    My MS CRM blog
    • Proposed as answer by Muhammad Ali Khan Wednesday, February 24, 2010 1:18 PM
    • Marked as answer by sini g Thursday, February 25, 2010 7:39 AM
    Wednesday, February 24, 2010 1:16 PM
  • Hi
    replace < with &lt; and > with &gt;(only in javascript)
    you have  to encode characters in xml.
    Muhammad Ali Khan
    My MS CRM blog
    • Marked as answer by sini g Thursday, February 25, 2010 10:27 AM
    Wednesday, February 24, 2010 1:32 PM
  • Try

    <Entity name="quote">
              <Grid>
                <MenuBar>
                  <Buttons>
                    <Button PassParams="1" WinMode="0" JavaScript="var selectedguid= getSelected('crmGrid');alert(selectedguid);">
                      <Titles>
                        <Title LCID="1033" Text="Cancel" />
                      </Titles>
                      <ToolTips>
                        <ToolTip LCID="1033" Text="Cancels the selected indent" />
                      </ToolTips>
                    </Button>
                  </Buttons>
                </MenuBar>
              </Grid>

    Regards
    Vinoth
    • Proposed as answer by VinothBalasubramanian Wednesday, February 24, 2010 1:36 PM
    • Marked as answer by sini g Thursday, February 25, 2010 7:38 AM
    Wednesday, February 24, 2010 1:34 PM
  • Provide us more information on the error

    try
    {

    // 1. Get all the Quote GUID

    string strCallerGuid = Request.Params["id"];
    string[] strRecordId = strCallerGuid.Split(new char[] { ',' });

    // 2. Cancel the Quote

    for (i = 0; i <strRecordId.Length; i++)
    {
    SetStateQuoteRequest state = new SetStateQuoteRequest();
    state.QuoteState = 3; //closed

    state.QuoteStatus = 6; //Cancelled
    state.EntityId = new GUID(strRecordId[i].ToString());

    SetStateQuoteResponse stateSet = (SetStateQuoteResponse)crmService.Execute(state);
    }

    catch (System.Web.Services.Protocols.SoapException ex) 

     Response.Write(ex.Message.tostring())

    catch (Exception e) 

    Response.Write(ex.ToString());
    Response.Write(ex.Detail.InnerText.ToString());
    Response.Write(ex.InnerException.ToString());


    Regards
    Vinoth

    • Marked as answer by sini g Thursday, February 25, 2010 1:11 PM
    Thursday, February 25, 2010 11:28 AM

All replies

  • Hi Sini.
    1) To get the selected rows, use this code.
    var a = document.all['crmGrid'].InnerGrid.SelectedRecords;
    var selectedItems = new Array(a.length);
    for (var i=0; i < a.length; i++)
    {
        selectedItems[i] = a[i][0];
    }
    alert(selectedItems);
    http://blog.customereffective.com/blog/2009/08/fun-with-the-crm-grid-object.html

    2) To convert the "Quote" status, use this message "SetStatusQuote".
    http://msdn.microsoft.com/en-us/library/bb959551.aspx
    and specify
    // Create the request object.
    SetStateQuoteRequest state = new SetStateQuoteRequest ();

    // Set the properties of the request object.
    state.QuoteState = AccountState.Closed;
    state.QuoteStatus = 5; // 5 means lost


    // EntityId is the GUID of the account whose state is being changed.
    state.EntityId = new Guid("AD618DB2-F0DB-4A6A-8C4B-2F2213EAA38E");;

    // Execute the request.
    SetStateQuoteResponse stateSet = (SetStateQuoteResponse )service.Execute(state);


    3)  Convert the above code in to javascript using the below.
    http://www.stunnware.com/crm2/topic.aspx?id=jswebservice2

    4) put the above code in the javascript="your javascript code here", in the ISV.config button.
    That's all :)



    Muhammad Ali Khan
    My MS CRM blog
    • Proposed as answer by Muhammad Ali Khan Wednesday, February 24, 2010 1:18 PM
    • Marked as answer by sini g Thursday, February 25, 2010 7:39 AM
    Wednesday, February 24, 2010 1:16 PM
  • Hey thanks for quick response.

    I tried doing it in ISV,

    _______________________________________________________________
    <Entity name="quote">
              <Grid>
                <MenuBar>
                  <Buttons>
                    <Button Icon="/_imgs/ico_18_debug.gif" Javascript="var a = document.all['crmGrid'].InnerGrid.SelectedRecords;
    var selectedItems = new Array(a.length);
    for(var i=0; i < a.length; i++)
    {
        selectedItems[i] = a[i][0];
    }
    alert(selectedItems);"
    Client="Web">
                      <Titles>
                        <Title LCID="1033" Text="Cancel" />
                      </Titles>
                      <ToolTips>
                        <ToolTip LCID="1033" Text="Cancels the selected indent" />
                      </ToolTips>
                    </Button>
                  </Buttons>
                </MenuBar>
              </Grid>
    ___________________________________________________________________-



    but got the below error



    _____________________________________________________________

     

    The character '<' cannot be used in an attribute value. Error processing resource 'file:///C:/Users/carecons3/Desktop/24th ...

     

    for(var i=0; i<a.length; i++) 
    --------------^

     

    -____________________________________________________________________
    sini_tg
    Wednesday, February 24, 2010 1:30 PM
  • Hi
    replace < with &lt; and > with &gt;(only in javascript)
    you have  to encode characters in xml.
    Muhammad Ali Khan
    My MS CRM blog
    • Marked as answer by sini g Thursday, February 25, 2010 10:27 AM
    Wednesday, February 24, 2010 1:32 PM
  • Try

    <Entity name="quote">
              <Grid>
                <MenuBar>
                  <Buttons>
                    <Button PassParams="1" WinMode="0" JavaScript="var selectedguid= getSelected('crmGrid');alert(selectedguid);">
                      <Titles>
                        <Title LCID="1033" Text="Cancel" />
                      </Titles>
                      <ToolTips>
                        <ToolTip LCID="1033" Text="Cancels the selected indent" />
                      </ToolTips>
                    </Button>
                  </Buttons>
                </MenuBar>
              </Grid>

    Regards
    Vinoth
    • Proposed as answer by VinothBalasubramanian Wednesday, February 24, 2010 1:36 PM
    • Marked as answer by sini g Thursday, February 25, 2010 7:38 AM
    Wednesday, February 24, 2010 1:34 PM
  • I am still getting errors while uploading it.
    sini_tg
    Wednesday, February 24, 2010 1:47 PM
  • Hi Srini

    Kindly let us know what error you are getting.
    Ensure to browse the XML bore uploading

    Regards
    Vinoth
    Wednesday, February 24, 2010 1:54 PM
  • hi,

    when applying this JS on the ISV file i am not getting error, but while uploading it in MSCRM, its showing error

    "Either the file could not be uploaded or this is not a valid customisation file"


    this is what i have added in ISV
    _______________________________________________________________________________
    - <Entity name="quote">
    - <Grid>
    - <MenuBar>
    - <Buttons>
    - <Button Icon="/_imgs/ico_18_debug.gif" Javascript="var a = document.all['crmGrid'].InnerGrid.SelectedRecords;var selectedItems = new Array(a.length);for (var i=0; i<a.length; i++){selectedItems[i] = a[i][0];}alert(selectedItems);" Client="Web">
    - <Titles>
      <Title LCID="1033" Text="Cancel" />
      </Titles>
    - <ToolTips>
      <ToolTip LCID="1033" Text="Cancels the selected indent" />
      </ToolTips>
      </Button>
      </Buttons>
      </MenuBar>
      </Grid>
    - <!--
     The Credit Limit Extension Request Tool Bar 
      -->
    - <ToolBar ValidForCreate="0" ValidForUpdate="1">
    - <Button Icon="/_imgs/ico_18_debug.gif" JavaScript="ChangeStatus(1);" Client="Web">
    - <Titles>
      <Title LCID="1033" Text="Approve" />
      </Titles>
    - <ToolTips>
      <ToolTip LCID="1033" Text="Approve" />
      </ToolTips>
      </Button>
      <ToolBarSpacer />
    - <Button Icon="/_imgs/ico_18_debug.gif" JavaScript="ChangeStatus(0);" Client="Web">
    - <Titles>
      <Title LCID="1033" Text="Reject" />
      </Titles>
    - <ToolTips>
      <ToolTip LCID="1033" Text="Reject" />
      </ToolTips>
      </Button>
      </ToolBar>
      </Entity>
    _________________________________________________________________________________-

    sini_tg
    Thursday, February 25, 2010 4:55 AM
  • replace   <     with   &lt;

    <
    Button Icon="/_imgs/ico_18_debug.gif"
    Javascript
    ="var a = document.all['crmGrid'].InnerGrid.SelectedRecords;
    var selectedItems = new Array(a.length);
    for (var i=0; i&lt;a.length; i++){selectedItems[i] = a[i][0];}alert(selectedItems);
    " Client="Web">
    http://www.allaboutdynamics.com
    Thursday, February 25, 2010 5:04 AM
  • Its working fine.
    Can anyone suggest me how to change the status code of these GUID's?
    sini_tg
    Thursday, February 25, 2010 6:18 AM
  • if you want to do this from C# then use SetStateQuote Message (CrmService)
    http://msdn.microsoft.com/en-us/library/bb959551.aspx

    you can do this using javascript from inside ISV
    http://www.allaboutdynamics.com
    Thursday, February 25, 2010 6:28 AM
  • SetStateQuoteRequest state = new SetStateQuoteRequest();
    state.QuoteState = 3; //closed

    state.QuoteStatus = 6; //Cancelled
    state.EntityId = quoteid;
                          
    SetStateQuoteResponse stateSet = (SetStateQuoteResponse)crmService.Execute(state);

    Regards
    Vinoth
    Thursday, February 25, 2010 6:42 AM
  • i am facing some problem while cancellation of the attribute status. My entity is quote and attribute is car_indentstatus.
    sini_tg
    Thursday, February 25, 2010 7:36 AM
  • can you please check this code and tell me what the error could be. i am getting unauthorised 401 error in the retrievemultipleresponse part.

    i have given the credentials and all in the code

     strCallerGuid = Request.Params["id"].ToString();
            string[] strRecordId = new String[100];
                Request.Params["id"].ToString();
                strRecordId = strCallerGuid.Split(',');
                int i;
            for(i=0;i<strRecordId.Length;i++)
                Response.Write(strRecordId[i]);

            #region "cancellation test"

           
            quote quotecol = new quote();
            SetStateQuoteRequest state = new SetStateQuoteRequest();

            ColumnSet cols = new ColumnSet();
            cols.Attributes = new string[] { "car_indentstatus" };

            // Create a ConditionExpression.
            ConditionExpression conditionIndent = new ConditionExpression();
            conditionIndent.AttributeName = "quoteid";
            conditionIndent.Operator = ConditionOperator.Equal;
            conditionIndent.Values = new object[strRecordId.Length];
            for(i=0;i<strRecordId.Length;i++)
                conditionIndent.Values[0] = strRecordId[i];

             // Create the FilterExpression.
             FilterExpression filterIndent = new FilterExpression();

             // Set the properties of the FilterExpression.
             filterIndent.FilterOperator = LogicalOperator.And;
             filterIndent.Conditions = new ConditionExpression[] { conditionIndent };

             // Create the QueryExpression.
             QueryExpression queryIndent = new QueryExpression();

             // Set the properties of the QueryExpression.
             queryIndent.EntityName = EntityName.quote.ToString();
             queryIndent.ColumnSet = cols;
             queryIndent.Criteria = filterIndent;

             // Create the request object.
             RetrieveMultipleRequest retrieveIndents= new RetrieveMultipleRequest();

             // Set the properties of the request object.
             retrieveIndents.Query = queryIndent;
         

             // Execute the request.
             RetrieveMultipleResponse result = null;
             result = service.Execute(retrieveIndents) as RetrieveMultipleResponse;
               
            //RetrieveMultipleResponse IndentsResponse = (RetrieveMultipleResponse)service.Execute(retrieveIndents);

             BusinessEntityCollection quote_col = service.RetrieveMultiple(queryIndent);
             for (i = 0; i < quote_col.BusinessEntities.Length; i++)
             {
               //  state.QuoteStatus = 6;
               //  state.EntityId = strRecordId;
                
             }
             SetStateQuoteResponse stateSet = (SetStateQuoteResponse)service.Execute(state);


    sini_tg
    Thursday, February 25, 2010 10:25 AM
  • Hi

    Can you explain us what is the use of car_indentstatus attribute?

    There is no need to perform the RetrieveMultiple operation. All the GUID of the Quote is already obtained. Hence we can directly close the Quote.

    Sample:

    // 1. Get all the Quote GUID

    string strCallerGuid = Request.Params["id"];
    string[] strRecordId = strCallerGuid.Split(new char[] { ',' });

    // 2. Cancel the Quote
    for (i = 0; i <strRecordId.Length; i++)
    {
    SetStateQuoteRequest state = new SetStateQuoteRequest();
    state.QuoteState = 3; //closed

    state.QuoteStatus = 6; //Cancelled
    state.EntityId = new GUID(strRecordId[i].ToString());

    SetStateQuoteResponse stateSet = (SetStateQuoteResponse)crmService.Execute(state);
    }


    Regards
    Vinoth
    Thursday, February 25, 2010 10:50 AM
  • QUote entity is renamed as indent and car_indentstatus is the quotestatus attribute.
    sini_tg
    Thursday, February 25, 2010 10:59 AM
  • i am getting the error

    System.Web.Services.Protocols.SoapException was unhandled by user code
      Message="Server was unable to process request."
      Source="System.Web.Services"
      Actor=""
      Lang=""
      Node=""
      Role=""
      StackTrace:
           at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
           at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
           at crmservice.CrmService.Execute(Request Request) in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\deletingindent\5c5deb0f\a6ce9781\App_WebReferences.v9bqomuj.0.cs:line 116
           at _Default.Page_Load(Object sender, EventArgs e) in c:\Users\carecons3\Documents\Visual Studio 2008\WebSites\deletingIndent\Default.aspx.cs:line 47
           at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
           at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
           at System.Web.UI.Control.OnLoad(EventArgs e)
           at System.Web.UI.Control.LoadRecursive()
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      InnerException:
    __________________________________________________________________-

    My code is:

     

    string strCallerGuid;

    strCallerGuid = Request.Params[

    "id"].ToString();

     

    string[] strRecordId = new String[100];

    Request.Params[

    "id"].ToString();

    strRecordId = strCallerGuid.Split(

    ',');

     

    int i;

     

    for (i = 0; i < strRecordId.Length; i++)

    {

     

    SetStateQuoteRequest state = new SetStateQuoteRequest();

     

    //state.QuoteState = 3; //closed

    state.QuoteStatus = 6;

    //Cancelled

     

    state.EntityId =

    new Guid(strRecordId[i].ToString());

     

    SetStateQuoteResponse stateSet = (SetStateQuoteResponse)service.Execute(state);

    Response.Write(

    "cencelled");

    }


    sini_tg
    Thursday, February 25, 2010 11:06 AM
  • Provide us more information on the error

    try
    {

    // 1. Get all the Quote GUID

    string strCallerGuid = Request.Params["id"];
    string[] strRecordId = strCallerGuid.Split(new char[] { ',' });

    // 2. Cancel the Quote

    for (i = 0; i <strRecordId.Length; i++)
    {
    SetStateQuoteRequest state = new SetStateQuoteRequest();
    state.QuoteState = 3; //closed

    state.QuoteStatus = 6; //Cancelled
    state.EntityId = new GUID(strRecordId[i].ToString());

    SetStateQuoteResponse stateSet = (SetStateQuoteResponse)crmService.Execute(state);
    }

    catch (System.Web.Services.Protocols.SoapException ex) 

     Response.Write(ex.Message.tostring())

    catch (Exception e) 

    Response.Write(ex.ToString());
    Response.Write(ex.Detail.InnerText.ToString());
    Response.Write(ex.InnerException.ToString());


    Regards
    Vinoth

    • Marked as answer by sini g Thursday, February 25, 2010 1:11 PM
    Thursday, February 25, 2010 11:28 AM
  • try

    state.QuoteStatus = -1;
    http://msdn.microsoft.com/en-us/library/cc154751.aspx

    Regards
    Vinoth
    Thursday, February 25, 2010 11:35 AM
  • I am getting the error

    "Server was unable to process request"

    thanks
    Sini
    sini_tg
    Thursday, February 25, 2010 11:44 AM
  • Thanks a ton Vinod.

    It worked.
    Probelm was with the code. I changed it from 6 and to the code which is in our cuustomisation and it worked fine. Thanks for the help.



    Sini
    sini_tg
    Thursday, February 25, 2010 12:21 PM
  • Hi Vinoth,

    where can i check the status of quote in this code?

    Thanks

    sini_tg
    Friday, February 26, 2010 9:27 AM