locked
Change Close Opportunity flow RRS feed

  • Question

  • Hi All,

    Can I change the flow of closing an Opportunity? Example:
    • add custom field into the Opportunity's closing form
    • add more requirement before the Opportunity can be closed (example: custom attribute X in Opportunity has to have value "y" )
    If it is possible, please let me know how to do it.

    Thank you for any help :)
    Friday, May 1, 2009 5:55 AM

Answers

  • Code to hide/unhide buttons that can be added to form load ...


    //****************************************************************************
    //
    // JSCRIPT FUNCTION FOR REMOVING TOP MENU BUTTONS AND SPACERS
    // Created : 26.08.2008 By: Morten Dybdahl, Capgemini
    //
    //****************************************************************************

    var Spacer = {
    Right : 1, // hides a right spacer if it exists
    Left : 2, // hides a left spacer if it exists
    Both : 3, // and so on...
    None : 4};

    var Display = {Show : "inline",Hide : "none"};

    function OnCrmPageLoad()
    {
       // Opportunity toolbar buttons
       if (crmForm.FormType < 3) ShowHideToolbarButton( "Save and New" , Spacer.None, Display.Hide );
       ShowHideToolbarButton( "Print Preview" , Spacer.None, Display.Hide );
       ShowHideToolbarButton( "Follow Up" , Spacer.None, Display.Hide );
        ShowHideToolbarButton( "Run Workflow" , Spacer.Right, Display.Hide );
       ShowHideToolbarButton( "Actions" , Spacer.None, Display.Hide );
       ShowHideToolbarButton( "Attach a File" , Spacer.Both, Display.Hide );
        if (crmForm.FormType != 4) ShowHideToolbarButton( "Click this button to Re-open opportunity." , Spacer.Left, Display.Hide);

    if (crmForm.FormType == 4)
    {
    ShowHideToolbarButton( "Click this button to set status to Won, and save and close screen. You will be able to retrieve it under Closed Opportunities." , Spacer.None, Display.Hide );

    ShowHideToolbarButton( "Click this button to set status to PUT ON HOLD, and save and close screen. You will be able to retrieve it under Closed Opportunities." , Spacer.None, Display.Hide );

    ShowHideToolbarButton( "Click this button to set status to LOST, and save and close screen. You will be able to retrieve it under Closed Opportunities." , Spacer.None, Display.Hide );

    ShowHideToolbarButton( "Click this button to set status to CANCELLED, and save and close screen. You will be able to retrieve it under Closed Opportunities." , Spacer.None, Display.Hide );

    if (document.getElementById('_MIreactivate') == null)
    {
    ShowHideToolbarButton( "Click this button to Re-open opportunity." , Spacer.Left, Display.Hide);
    }
    }
    }

    function ShowHideToolbarButton( btnTitle , spacer , state )
    {
       if( isNullOrEmpty( btnTitle ))
       return;

       if( isNullOrEmpty( spacer ) )
       spacer = ToolbarSpacer.None;

       if( isNullOrEmpty( state ) )
       state = ButtonDisplay.Hide;

       //Get all toolbar buttons
       var toolBarButtons = document.all.mnuBar1.rows[0].cells[0].childNodes[0].childNodes;

       //Loop through each button
       for (var i = 0 ; i < toolBarButtons.length ; i++)
       {
          var button = toolBarButtons[i];
          if( button.title == btnTitle )
          {
             button.style.display = state;
             switch(spacer)
          {
               case Spacer.Right: ShowHideSpacer( button.nextSibling ); break;
               case Spacer.Left: ShowHideSpacer( button.previousSibling ); break;
               case Spacer.Both: ShowHideSpacer( button.nextSibling );
               ShowHideSpacer( button.previousSibling ); break;
          }
          return;
       }
    }

    function ShowHideSpacer( btnSpacer ){if( !isNullOrEmpty( btnSpacer ) ) btnSpacer.style.display = state;}
    function isNullOrEmpty( obj ){return obj == null || typeof(obj) == "undefined" || obj == "";}
    }
    OnCrmPageLoad();

    Friday, May 1, 2009 6:16 AM

All replies

  • Hi,

    Change the opportunity close form is difficult, don't do that, no config possibilities. But to get control over the closing process. I have worked with similar requirements, and we created 3 isv buttons to close the opportunity (that also could check that a number of fields are filled in before allow to close).

    _____________________________________________________________________________
    Hide the buttons that now will be redundant
    (assume you know how to do that ...)
    _______________________________________________________________________
    ISV CONFIG (you must check that the id of the closing values match your codes)
    __________________________________________________________________

    <Entity name="opportunity">
              <ToolBar>
                <Button Icon="/_imgs/ico_18_org.gif" JavaScript="reactivate();" ValidForCreate="0">
                  <Titles>
                    <Title LCID="1033" Text="Re-open" />
                  </Titles>
                  <ToolTips>
                    <ToolTip LCID="1033" Text="Click this button to Re-open opportunity." />
                  </ToolTips>
                </Button>
                <Button Icon="/_imgs/ico_18_9105.gif" JavaScript="document.closeopportunityaswon('3','Opportunity Closed as Won');" ValidForCreate="0">
                  <Titles>
                    <Title LCID="1033" Text="Won" />
                  </Titles>
                  <ToolTips>
                    <ToolTip LCID="1033" Text="Click this button to set status to Won, and save and close screen. You will be able to retrieve it under Closed Opportunities." />
                  </ToolTips>
                </Button>
                <Button Icon="/_imgs/ico_16_remove.gif" JavaScript="document.closeopportunityaslost('4','Opportunity Closed as On Hold');" ValidForCreate="0">
                  <Titles>
                    <Title LCID="1033" Text="Hold" />
                  </Titles>
                  <ToolTips>
                    <ToolTip LCID="1033" Text="Click this button to set status to PUT ON HOLD, and save and close screen. You will be able to retrieve it under Closed Opportunities." />
                  </ToolTips>
                </Button>
                <Button Icon="/_imgs/ico_16_remove.gif" JavaScript="document.closeopportunityaslost('5','Opportunity Closed as Lost');" ValidForCreate="0">
                  <Titles>
                    <Title LCID="1033" Text="Lost" />
                  </Titles>
                  <ToolTips>
                    <ToolTip LCID="1033" Text="Click this button to set status to LOST, and save and close screen. You will be able to retrieve it under Closed Opportunities." />
                  </ToolTips>
                </Button>
              </ToolBar>
            </Entity>

    ________________________________________________________________________________________
    Add this code to your form load
    __________________________________________________________________________________________

    //**********************************************************************
    //
    //  JSCRIPT FOR SETTING QUOTE STATE AND STATUS TO CLOSING STATUS
    //  Created By: Morten Dybdahl, Capgeminil     Created On: 19.03.2009
    //
    //**********************************************************************
    function document.closeopportunityaslost(closecode, subject)
    {
    var authenticationHeader = GenerateAuthenticationHeader();
    var opportunityId = crmForm.ObjectId;
    var xml = "<?xml version='1.0' encoding='utf-8'?>"+
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
    authenticationHeader+
    "<soap:Body>"+
    "<Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
    "<Request xsi:type='LoseOpportunityRequest'>"+
    "<OpportunityClose xsi:type='opportunityclose'>"+
    "<opportunityid type='opportunity'>"+opportunityId+"</opportunityid>"+
    "<subject>" + subject + "</subject>"+
    "</OpportunityClose>"+
    "<Status>" + closecode + "</Status>"+
    "</Request>"+
    "</Execute>"+
    "</soap:Body>"+
    "</soap:Envelope>";
    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);
    var resultXml = xHReq.responseXML;
    var errorCount = resultXml.selectNodes('//error').length;
    if (errorCount != 0){
    var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
    alert(msg);}
    else{alert("Opportunity is now closed"); crmForm.SaveAndClose();}
    }

    function document.closeopportunityaswon(closecode, subject)
    {
    var authenticationHeader = GenerateAuthenticationHeader();
    var opportunityId = crmForm.ObjectId;
    var xml = "<?xml version='1.0' encoding='utf-8'?>"+
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
    authenticationHeader+
    "<soap:Body>"+
    "<Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
    "<Request xsi:type='WinOpportunityRequest'>"+
    "<OpportunityClose xsi:type='opportunityclose'>"+
    "<opportunityid type='opportunity'>"+opportunityId+"</opportunityid>"+
    "<subject>" + subject + "</subject>"+
    "</OpportunityClose>"+
    "<Status>" + closecode + "</Status>"+
    "</Request>"+
    "</Execute>"+
    "</soap:Body>"+
    "</soap:Envelope>";
    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);
    var resultXml = xHReq.responseXML;
    var errorCount = resultXml.selectNodes('//error').length;
    if (errorCount != 0){
    var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
    alert(msg);}
    else{alert("Opportunity is now closed as Won"); crmForm.SaveAndClose();}
    }

     

    Friday, May 1, 2009 6:12 AM
  • Code to hide/unhide buttons that can be added to form load ...


    //****************************************************************************
    //
    // JSCRIPT FUNCTION FOR REMOVING TOP MENU BUTTONS AND SPACERS
    // Created : 26.08.2008 By: Morten Dybdahl, Capgemini
    //
    //****************************************************************************

    var Spacer = {
    Right : 1, // hides a right spacer if it exists
    Left : 2, // hides a left spacer if it exists
    Both : 3, // and so on...
    None : 4};

    var Display = {Show : "inline",Hide : "none"};

    function OnCrmPageLoad()
    {
       // Opportunity toolbar buttons
       if (crmForm.FormType < 3) ShowHideToolbarButton( "Save and New" , Spacer.None, Display.Hide );
       ShowHideToolbarButton( "Print Preview" , Spacer.None, Display.Hide );
       ShowHideToolbarButton( "Follow Up" , Spacer.None, Display.Hide );
        ShowHideToolbarButton( "Run Workflow" , Spacer.Right, Display.Hide );
       ShowHideToolbarButton( "Actions" , Spacer.None, Display.Hide );
       ShowHideToolbarButton( "Attach a File" , Spacer.Both, Display.Hide );
        if (crmForm.FormType != 4) ShowHideToolbarButton( "Click this button to Re-open opportunity." , Spacer.Left, Display.Hide);

    if (crmForm.FormType == 4)
    {
    ShowHideToolbarButton( "Click this button to set status to Won, and save and close screen. You will be able to retrieve it under Closed Opportunities." , Spacer.None, Display.Hide );

    ShowHideToolbarButton( "Click this button to set status to PUT ON HOLD, and save and close screen. You will be able to retrieve it under Closed Opportunities." , Spacer.None, Display.Hide );

    ShowHideToolbarButton( "Click this button to set status to LOST, and save and close screen. You will be able to retrieve it under Closed Opportunities." , Spacer.None, Display.Hide );

    ShowHideToolbarButton( "Click this button to set status to CANCELLED, and save and close screen. You will be able to retrieve it under Closed Opportunities." , Spacer.None, Display.Hide );

    if (document.getElementById('_MIreactivate') == null)
    {
    ShowHideToolbarButton( "Click this button to Re-open opportunity." , Spacer.Left, Display.Hide);
    }
    }
    }

    function ShowHideToolbarButton( btnTitle , spacer , state )
    {
       if( isNullOrEmpty( btnTitle ))
       return;

       if( isNullOrEmpty( spacer ) )
       spacer = ToolbarSpacer.None;

       if( isNullOrEmpty( state ) )
       state = ButtonDisplay.Hide;

       //Get all toolbar buttons
       var toolBarButtons = document.all.mnuBar1.rows[0].cells[0].childNodes[0].childNodes;

       //Loop through each button
       for (var i = 0 ; i < toolBarButtons.length ; i++)
       {
          var button = toolBarButtons[i];
          if( button.title == btnTitle )
          {
             button.style.display = state;
             switch(spacer)
          {
               case Spacer.Right: ShowHideSpacer( button.nextSibling ); break;
               case Spacer.Left: ShowHideSpacer( button.previousSibling ); break;
               case Spacer.Both: ShowHideSpacer( button.nextSibling );
               ShowHideSpacer( button.previousSibling ); break;
          }
          return;
       }
    }

    function ShowHideSpacer( btnSpacer ){if( !isNullOrEmpty( btnSpacer ) ) btnSpacer.style.display = state;}
    function isNullOrEmpty( obj ){return obj == null || typeof(obj) == "undefined" || obj == "";}
    }
    OnCrmPageLoad();

    Friday, May 1, 2009 6:16 AM
  • cool...

    thanks for the option :) i'll try it.

    Friday, May 1, 2009 6:50 AM