locked
Add Save & Next button to Activity CRM 4.0 RRS feed

  • Question

  • I would like to add a Save & Next button to the toolbar in the Activity form (and other forms like Contact for that matter).

    Not sure even where to begin with this. Any ideas? Javscript or .NET ??

    Cheers,
    Brett
    Thursday, July 17, 2008 4:22 AM

Answers

  • Hi,

     

    I think that you can achieve that with JavaScript. The CRM's isv.config file let you add new buttons to entitie's forms. These buttons can call another url, or run javascript code. You will need to export the isv.config file from the export customizations area, then add the the button, and finally import the new isv.config file. Take a look on the SDK to the section that explains how to add new buttons.

     

    The code for the button should follow a flow like this:

     

    - Call CRM Web Services to retrieve the next activity id.

    - Use window.open to launch a new dialog with the form of the activity (edit.asp?id={.....}) Refer to URL addressable forms on the SDK to find out more on how to open the forms.

    - Call crmForm.SaveAndClose() to close the current activity form.

     

    I recommend you to take a look to Michael Hoehne's blog about that includes a very handy tool to generate the JavaScript for calling the CRM Web Service

    http://www.dynamicscrmkicks.com/Development/Calling_the_CRM_Web_Service_with_JavaScrip.aspx

     

    Hope it helps,

    Marco

    Thursday, July 17, 2008 9:43 AM
    Moderator

All replies

  • Hi,

     

    I think that you can achieve that with JavaScript. The CRM's isv.config file let you add new buttons to entitie's forms. These buttons can call another url, or run javascript code. You will need to export the isv.config file from the export customizations area, then add the the button, and finally import the new isv.config file. Take a look on the SDK to the section that explains how to add new buttons.

     

    The code for the button should follow a flow like this:

     

    - Call CRM Web Services to retrieve the next activity id.

    - Use window.open to launch a new dialog with the form of the activity (edit.asp?id={.....}) Refer to URL addressable forms on the SDK to find out more on how to open the forms.

    - Call crmForm.SaveAndClose() to close the current activity form.

     

    I recommend you to take a look to Michael Hoehne's blog about that includes a very handy tool to generate the JavaScript for calling the CRM Web Service

    http://www.dynamicscrmkicks.com/Development/Calling_the_CRM_Web_Service_with_JavaScrip.aspx

     

    Hope it helps,

    Marco

    Thursday, July 17, 2008 9:43 AM
    Moderator
  • Thanks mate. Legendary - looks like exactly what I need and that utility is perfect.
    Friday, July 18, 2008 4:50 AM
  • After much searching and experimenting, here's something that actually works.  For 4.0, Here's some code that will get this working with Next & Previous buttons.  This is an adaptation of several other posts I've found, none of which saved and went to the next (or previous records).  The next trick is to figure out when it fails to save (b/c of a missing field or whatever) and handle that exception.  Place this into the ISV.Customizations.xml file and import.

          <Entities>
    <!-- ACCOUNT Save and Next modifications -->
            <Entity name="account">
              <ToolBar ValidForCreate="0" ValidForUpdate="1">
                <Button Icon="/_imgs/previous.gif" JavaScript="crmForm.Save(); if(window.opener.document.all['crmGrid'] != null) { var _cwrRecordIndex; var _cwrGrid=window.opener.document.all['crmGrid'].InnerGrid; var _cwrRecords=_cwrGrid.AllRecords; for(var i=0; i&lt;_cwrRecords.length; i++){if(_cwrRecords[i][0] == crmForm.ObjectId){if(i!=0){window.location.href=window.location.href.split('?')[0]+'?id='+_cwrRecords[i-1][0];_cwrGrid.UnselectRecords();_cwrGrid.SelectRecords(i-1,i-1,false);}}}}else{alert('This button only works when the record is opened from a grid.');}">
                  <Titles>
                    <Title LCID="1034" Text="Previous" />
                  </Titles>
                </Button>
                <Button Icon="/_imgs/next.gif" JavaScript="crmForm.Save(); if(window.opener.document.all['crmGrid'] != null) { var _cwrRecordIndex; var _cwrGrid=window.opener.document.all['crmGrid'].InnerGrid; var _cwrRecords=_cwrGrid.AllRecords; for(var i=0; i&lt;_cwrRecords.length; i++){if(_cwrRecords[i][0] == crmForm.ObjectId){if(i!=_cwrRecords.length-1){window.location.href=window.location.href.split('?')[0]+'?id='+_cwrRecords[i+1][0];_cwrGrid.UnselectRecords();_cwrGrid.SelectRecords(i+1,i+1,false);}}}}else{alert('This button only works when the record is opened from a grid.');}">
                  <Titles>
                    <Title LCID="1034" Text="Next" />
                  </Titles>
                </Button>
            <ToolBarSpacer />
              </ToolBar>
            </Entity>
    <!-- LEAD Save and Next modifications -->
            <Entity name="lead">
              <ToolBar ValidForCreate="0" ValidForUpdate="1">
                <Button Icon="/_imgs/previous.gif" JavaScript="crmForm.Save(); if(window.opener.document.all['crmGrid'] != null) { var _cwrRecordIndex; var _cwrGrid=window.opener.document.all['crmGrid'].InnerGrid; var _cwrRecords=_cwrGrid.AllRecords; for(var i=0; i&lt;_cwrRecords.length; i++){if(_cwrRecords[i][0] == crmForm.ObjectId){if(i!=0){window.location.href=window.location.href.split('?')[0]+'?id='+_cwrRecords[i-1][0];_cwrGrid.UnselectRecords();_cwrGrid.SelectRecords(i-1,i-1,false);}}}}else{alert('This button only works when the record is opened from a grid.');}">
                  <Titles>
                    <Title LCID="1034" Text="Previous" />
                  </Titles>
                </Button>
                <Button Icon="/_imgs/next.gif" JavaScript="crmForm.Save(); if(window.opener.document.all['crmGrid'] != null) { var _cwrRecordIndex; var _cwrGrid=window.opener.document.all['crmGrid'].InnerGrid; var _cwrRecords=_cwrGrid.AllRecords; for(var i=0; i&lt;_cwrRecords.length; i++){if(_cwrRecords[i][0] == crmForm.ObjectId){if(i!=_cwrRecords.length-1){window.location.href=window.location.href.split('?')[0]+'?id='+_cwrRecords[i+1][0];_cwrGrid.UnselectRecords();_cwrGrid.SelectRecords(i+1,i+1,false);}}}}else{alert('This button only works when the record is opened from a grid.');}">

                  <Titles>
                    <Title LCID="1034" Text="Next" />
                  </Titles>
                </Button>
              </ToolBar>
            </Entity>

            <Entity name="lead">
              <!-- The Account Tool Bar -->
              <ToolBar ValidForCreate="0" ValidForUpdate="1">
                <Button Icon="/_imgs/next.gif" JavaScript="if(window.opener.document.all['crmGrid'] != null) { var _cwrRecordIndex; var _cwrGrid=window.opener.document.all['crmGrid'].InnerGrid; var _cwrRecords=_cwrGrid.AllRecords; for(var i=0; i&lt;_cwrRecords.length; i++){if(_cwrRecords[i][0] == crmForm.ObjectId){if(i!=0){window.location.href=window.location.href.split('?')[0]+'?id='+_cwrRecords[i-1][0];_cwrGrid.UnselectRecords();_cwrGrid.SelectRecords(i-1,i-1,false);}}}}else{alert('This button only works when the record is opened from a grid.');}">
                  <Titles>
                    <Title LCID="1033" Text="Next" />
                  </Titles>
                  <ToolTips>
                    <ToolTip LCID="1033" Text="Previous Record" />
                  </ToolTips>
                </Button>
                <ToolBarSpacer />
                <Button Icon="/_imgs/previous.gif" Url="http://www.microsoft.com" PassParams="1" WinParams="" WinMode="1">
                  <Titles>
                    <Title LCID="1033" Text="Previous" />
                  </Titles>
                  <ToolTips>
                    <ToolTip LCID="1033" Text="Previous Record" />
                  </ToolTips>
                </Button>   
            <ToolBarSpacer />
              </ToolBar>
    Thursday, May 21, 2009 12:24 AM
  • Hi Provino

    I'm Using CRM 4.0 i have the above code as is an d exported the ISV.Config file . opened the file Visual Studio and pasted. then i published all the entities.

    when i opened the record n saw there was no buttons added in the entity

    Tell me from step 1 how to implement Next & Previous Button in CRM 4.0 for custom & System Entity

    Thanks,

    Saraswathy

    Tuesday, August 10, 2010 7:07 AM
  • Hello,

    Maybe you need to switch on ISV.config customizations in the system?

    Go to Settings->Administration->System Settings -> Customization tab -> Custom menus & toolbars

    and ensure it is set to show in the client you are using.

    Regards,

    JdZ

    Tuesday, August 10, 2010 7:35 AM
  • HI JdZ,

    I have just pasted the same coding i didnt even change a single character from the above coding. i have also checked Custom menus & toolbars & choosed webclient even after that its not working

    i'm very eager to Place Next previous button concept for system entity

    Thanks,

    Saraswathy

     

    Tuesday, August 10, 2010 7:45 AM
  • If CRM accepted the new ISV.config file without throwing an error is means the file parsed ok, so it should show.

    • Maybe you could re-export the ISV.config file to ensure your changes did get saved?
    • Also closing internet exporer and reopen it might help?
    • Also the code above includes a line that says this will only show in update mode? Are you pressing 'new' during your testing instead of finding an existing record?
      ToolBar ValidForCreate="0" ValidForUpdate="1"

    If those three don't work im out of ideas.

    JdZ

     

    Tuesday, August 10, 2010 8:43 AM
  • JDZ

    Do you who to assign a keyboard shortcut to the above forward and next button?

    Thanks

    Jas

    Tuesday, September 14, 2010 7:56 PM