Drawloop - Merge Documents by Alphabetical Order - DocGen Queue

  • 15 February 2022
  • 0 replies
  • 179 views

Userlevel 5
Badge +19

Topic

How to Merge Documents by Alphabetical Order in the DocGen Queue

 

Instructions

** This Sample button will not be supported for any additional modification. This button falls under the realm of custom buttons.
 

  1. Navigate to Salesforce setup
    1. Search in Quick Find “Visualforce Pages”
    2. Click “New”
    3. Give the Page a ‘Label’ & ‘Name’
                      (Sample)
      1. Label = ‘Drawloop - Order DocQ by Name’
      2. Name = ‘Drawloop_Order_DocQ_by_Name’
         
    4. Copy the below Visualforce page sample and paste it in the ‘Visualforce Markup’ Section.
    5. Click Save.
       
  2. Navigate to Salesforce Setup
    1. Search in Salesforce setup > Object Manager
    2. Select the “Document Request” object.
    3. Under ‘Buttons, Links, and Actions’ Select ‘New Button or Link’
    4. Give the Button a ‘Label’ & ‘Name’
                      (Sample)
      1. Label = ‘Merge by Name’
      2. Name = ‘Merge_by_Name’
         
    5. Select Display type = ‘List Button’
    6. Select Behavior = ‘Display in existing window with sidebar’
    7. Select Content Type = ‘Visualforce Page’
    8. Select Content = ‘Drawloop - Order DocQ by Name’
    9. Click ‘Save’
       
  3. Navigate back to the ‘Document Request object’ to add your button to the page layout.
    1. Now, Navigate to  ‘Search Layout’ on the ‘Document Request object’
    2. Select ‘List View Button Layout'
    3. Select Edit from the dropdown on the 'List View Layout’
    4. Move the newly created button from ‘Available Buttons’ to ‘Selected Buttons’
    5. Click ‘Save’

 
Now Navigate to the Document Queue and merge the selected files. They will merge in alphabetical order.
 

Additional Information

 

<apex:page standardController="Loop__Document_Request__c" recordSetVar="units">
    <apex:includeScript value="/soap/ajax/26.0/connection.js"/>
    <apex:includeScript value="/support/console/26.0/integration.js"/>

<apex:dataTable value="{!selected}" var="un">
    <apex:column >
        <apex:outputLabel styleClass="ids">{!un.Id}</apex:outputLabel>
    </apex:column>
</apex:dataTable>
<style>
.ids{visibility : hidden}
</style>

<script type="text/javascript">
    document.addEventListener("DOMContentLoaded", function(event) {
        debugger;
        sforce.connection.sessionId = '{!$Api.Session_ID}'; 
        var elems = document.body.getElementsByClassName("ids");
        var ids = new Array();

        for (var i = elems.length - 1; i >= 0; i--) {
            //the \n is regex for line break
            ids[i] = elems[i].innerHTML.replace(/\n/, '');   
        }
        if (ids.length < 1) {
            
            alert("No items are currently selected.");
        } else {
            var docIds = new Array();
            var updatedIds = new Array();
            try { 
                var qr = sforce.connection.query("SELECT Loop__Document_Id__c FROM Loop__Document_Request__cWHERE Id IN ('"+ ids.join("','") +"') ORDER by Loop__Document_Name__c");
            } catch(e) { console.log(e); alert('An error has occurred. Please try again.'); return; }
            if (qr.size > 0)
            {
                for (var i=0; i < qr.size; i++)
                {
                    q = (qr.records[i] ? qr.records[i] : qr.records);
                    if(q && q.Loop__Document_Id__c && q.Loop__Document_Id__c.substring(0,3) == '015')
                    {
                        docIds.push(q.Loop__Document_Id__c);
                        var request = new sforce.SObject("Loop__Document_Request__c");
                        request.Id = ids[i];
                        request.Loop__Status__c = "Merged";
                        updatedIds.push(request);
                    }
                }
            }
            try { sforce.connection.update(updatedIds);
                } catch(e) { alert("Unable to update all requests' statuses."); }
            {
          var redirectUrl = "/apex/loop__loopit?eid=" + ids[0] + "&docIds=" + docIds.join('-') + "&type=merge" + "&mergetype=bytype";

           if (sforce && sforce.one && sforce.one.navigateToURL) {
   sforce.one.navigateToURL(redirectUrl);
} else {
         window.location.href = redirectUrl;
         }
        }
       }
       });

</script>
</apex:page>

 

 


0 replies

Be the first to reply!

Reply