cancel
Showing results for 
Search instead for 
Did you mean: 

Merge Documents by Alphabetical Order - Document Queue

Topic

How to Merge Documents by Alphabetical Order in the Document 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 attached Visualforce page code and paste it in the ‘Visualforce Markup’ Section.
    5. Click Save.
       
  2. Navigate to Salesforce Setup
    1. Search in Quick Find “objects”
    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 ‘Edit on ‘DocGen Queue List View’
    3. Move the newly created button from ‘Available Buttons’ to ‘Selected Buttons’
    4. 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__c WHERE 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."); }
            window.parent.location = "/apex/loop__loopit?eid=" + ids[0] + "&docIds=" + docIds.join('-') + "&type=merge";
        }
    });
      
</script>
</apex:page>

 

Labels: (2)
Version history
Revision #:
41 of 41
Last update:
‎02-28-2019 07:20 AM
Updated by: