none
Custom Print Button on Infopath List EditForm not showing

    Question

  •  

      Here is the code i created to add a print button on an Infopath List edit form.

    When I chaneg the location to the display form the button show fine, however when i try and put it on the

    edit form it does not show. Can anyone give me a reason why it doesn't show?<CustomAction Id="Ribbon.InfoPath.Actions.AddCustomButton"
         Location="CommandUI.Ribbon.EditForm"
               Title="PrintButton"
               xmlns="http://schemas.microsoft.com/sharepoint/">


        <CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
          <CommandUIDefinitions>
            <CommandUIDefinition Location="Ribbon.ListForm.Edit.Actions.Controls._Children">
              <Button Id="Ribbon.ListForm.Edit.Actions.Controls.Print"
                      Command="Print"
                      LabelText="Print Item"
                      Sequence="16"
                      TemplateAlias="o2"
                      Image16by16="/_layouts/images/printer.png"
                      Image32by32="/_layouts/images/printer.png"/>
            </CommandUIDefinition>
          </CommandUIDefinitions>
          <CommandUIHandlers>
            <CommandUIHandler
               Command="Print"
                   CommandAction="javascript:
                              var patt = /.+_FormControl.+__ViewContainer/gi;
                              var alldivs = document.getElementsByTagName('div');
                              var printpageHTML = '';
                              for(var i=0; i&lt;alldivs.length; i++){
                                if(patt.test(alldivs[i].id)){
                                  printpageHTML = '&lt;HTML&gt;&lt;HEAD&gt;\n' +
                                                  document.getElementsByTagName('HEAD')[0].innerHTML +
                                                  '&lt;/HEAD&gt;\n&lt;BODY&gt;\n' +
                                                  alldivs[i].innerHTML.replace('inline-block','block') +
                                                  '\n&lt;/BODY&gt;&lt;/HTML&gt;';
                                  break;
                                }
                              }
                              var printWindow = window.open('','printWindow');
                              printWindow.document.open();
                              printWindow.document.write(printpageHTML);
                              printWindow.document.close();
                              printWindow.print();
                              printWindow.close();
                              SP.UI.Notify.addNotification('Exiting!');

                             
                               ">

            </CommandUIHandler>
          </CommandUIHandlers>
        </CommandUIExtension>
      </CustomAction>
     
        

     



    • Edited by cw6050 Wednesday, December 19, 2012 12:14 AM
    Tuesday, December 18, 2012 10:47 PM

Answers

  • Hi cw6050,

    Please add the RegistrationId and RegistrationType attributes in CustomAction tag, and also specify the CommandUIDefinition tag Location as "Ribbon.DocLibListForm.Edit.Actions.Controls._children", 

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <CustomAction Id="Ribbon.InfoPath.Actions.AddCustomButton"
                     Location="CommandUI.Ribbon.EditForm"
                    Title="PrintButton"
                   RegistrationId="115"
                   RegistrationType="List" >
    
        <CommandUIExtension >
          <CommandUIDefinitions>
            <CommandUIDefinition Location="Ribbon.DocLibListForm.Edit.Actions.Controls._children">
              <Button Id="Ribbon.DocLibListForm.Edit.Actions.Controls.Print"
                      Command="Print"
                      LabelText="Print Item"
                      Sequence="16"
                      TemplateAlias="o2"
                      Image16by16="/_layouts/images/printer.png"
                      Image32by32="/_layouts/images/printer.png"/>
            </CommandUIDefinition>
          </CommandUIDefinitions>
          <CommandUIHandlers>
            <CommandUIHandler
               Command="Print"
                   CommandAction="javascript:
                              var patt = /.+_FormControl.+__ViewContainer/gi;
                              var alldivs = document.getElementsByTagName('div');
                              var printpageHTML = '';
                              for(var i=0; i&lt;alldivs.length; i++){
                                if(patt.test(alldivs[i].id)){
                                  printpageHTML = '&lt;HTML&gt;&lt;HEAD&gt;\n' +
                                                  document.getElementsByTagName('HEAD')[0].innerHTML +
                                                  '&lt;/HEAD&gt;\n&lt;BODY&gt;\n' + 
                                                  alldivs[i].innerHTML.replace('inline-block','block') + 
                                                  '\n&lt;/BODY&gt;&lt;/HTML&gt;';
                                  break;
                                }
                              }
                              var printWindow = window.open('','printWindow');
                              printWindow.document.open();
                              printWindow.document.write(printpageHTML);
                              printWindow.document.close();
                              printWindow.print();
                              printWindow.close(); 
                              SP.UI.Notify.addNotification('Exiting!');                           
                               ">
    
            </CommandUIHandler>
          </CommandUIHandlers>
        </CommandUIExtension>
      </CustomAction>
    </Elements>

    Thanks


    Daniel Yang
    TechNet Community Support

    Thursday, December 20, 2012 10:39 AM
    Moderator

All replies

  • Hi cw6050,

    Please add the RegistrationId and RegistrationType attributes in CustomAction tag, and also specify the CommandUIDefinition tag Location as "Ribbon.DocLibListForm.Edit.Actions.Controls._children", 

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <CustomAction Id="Ribbon.InfoPath.Actions.AddCustomButton"
                     Location="CommandUI.Ribbon.EditForm"
                    Title="PrintButton"
                   RegistrationId="115"
                   RegistrationType="List" >
    
        <CommandUIExtension >
          <CommandUIDefinitions>
            <CommandUIDefinition Location="Ribbon.DocLibListForm.Edit.Actions.Controls._children">
              <Button Id="Ribbon.DocLibListForm.Edit.Actions.Controls.Print"
                      Command="Print"
                      LabelText="Print Item"
                      Sequence="16"
                      TemplateAlias="o2"
                      Image16by16="/_layouts/images/printer.png"
                      Image32by32="/_layouts/images/printer.png"/>
            </CommandUIDefinition>
          </CommandUIDefinitions>
          <CommandUIHandlers>
            <CommandUIHandler
               Command="Print"
                   CommandAction="javascript:
                              var patt = /.+_FormControl.+__ViewContainer/gi;
                              var alldivs = document.getElementsByTagName('div');
                              var printpageHTML = '';
                              for(var i=0; i&lt;alldivs.length; i++){
                                if(patt.test(alldivs[i].id)){
                                  printpageHTML = '&lt;HTML&gt;&lt;HEAD&gt;\n' +
                                                  document.getElementsByTagName('HEAD')[0].innerHTML +
                                                  '&lt;/HEAD&gt;\n&lt;BODY&gt;\n' + 
                                                  alldivs[i].innerHTML.replace('inline-block','block') + 
                                                  '\n&lt;/BODY&gt;&lt;/HTML&gt;';
                                  break;
                                }
                              }
                              var printWindow = window.open('','printWindow');
                              printWindow.document.open();
                              printWindow.document.write(printpageHTML);
                              printWindow.document.close();
                              printWindow.print();
                              printWindow.close(); 
                              SP.UI.Notify.addNotification('Exiting!');                           
                               ">
    
            </CommandUIHandler>
          </CommandUIHandlers>
        </CommandUIExtension>
      </CustomAction>
    </Elements>

    Thanks


    Daniel Yang
    TechNet Community Support

    Thursday, December 20, 2012 10:39 AM
    Moderator
  •  Thanks but the button does not show up on the Edit Item eventhough it appears to be coded correctly - can only get it to show up on the Display

    The feature has been activated

    Wednesday, January 02, 2013 7:07 PM
  • Thanks for sharing your print code.  This is especially good because it captures just the form.   

    One gotcha I notice is that page breaks set in the InfoPath form are not honored.


    /bac

    Sunday, March 10, 2013 12:21 PM
  • I'm working on this too.  I think Daniel's code might be for a Form library, not a list with a customized Edit Form.

    /bac

    Sunday, March 10, 2013 12:32 PM