Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

docusignapextoolkit - Docusign Apextoolkit - Envelope sent does not show under DocuSign Status related list

I'm able to generate an envelope from a template and it is properly overlaying as expected from the provided Opportunity Object Id. It's not updating the Docusign Status related list however, and from the documentation this should automatically be occurring from Docusign. What am I missing from this process?

    /**
 * @description Accepts the Id of the associated primary object the envelope is being sent from.
 * @param mySourceId 
 */
public static void methodSendEnvelope(Id mySourceId) {
    final string METHOD_NAME = 'SendEnvelope';
    System.debug(CLASS_NAME + '.' + METHOD_NAME);
    Boolean readyToProcess = false;
    dfsle.Envelope myEnvelope = null;

    //pickup the predefined object to template association
    final Map<String, Docusign_YPO_Setting__mdt> settingsDocusignTemplate = new Map<String, Docusign_YPO_Setting__mdt> ();
    For (Docusign_YPO_Setting__mdt settingItem :[Select Label, Template_Name__c, Template_ID__c,
         reminder__c, remindAfterDays__c, reminderFrequencyDays__c,
         expires__c, expiresAfterDays__c, expireWarnDays__c,
         email_Subject__c, email_Body__c
         From Docusign_YPO_Setting__mdt]) {
        settingsDocusignTemplate.put(settingItem.Label, settingItem);
    }

    //obtain the template for the envelope
    String sourceName = idObjectName(mySourceId);

    emailRecipent sender = new emailRecipent();

    Map<String, object> templateInfo = new Map<String, object> ();

    //if (settingsDocusignTemplate.get(sourceName) != null) {
    //System.debug('Looking for Template: ' + settingsDocusignTemplate.get(sourceName).Template_Name__c);
    //templateInfo = findTemplate(settingsDocusignTemplate.get(sourceName).Template_Name__c);
    //}

    switch on sourceName {
        //when 'Lead' {
        //lead whoTo = [Select Id, FirstName, LastName, X3rd_Party_Email__c, X3rd_Party_Name__c From Lead Where id = :mySourceId];
        //System.debug(whoTo);
        //sender.name = whoTo.X3rd_Party_Name__c;
        //sender.eAddress = whoTo.X3rd_Party_Email__c;
        //sender.role = 'Signer 1';
        //readyToProcess = true;

        //templateInfo.put('Source_Reference', (String) mySourceId + '~Lead');
        //templateInfo.put('UUID', dfsle.UUID.tryparse('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'));
        //templateInfo.put('name', 'Lead Third Party Validation');
        //}
        when 'Opportunity' {
            Opportunity whoTo = [Select Id, Contact__c, Third_Party_Email__c, Third_Party_Name__c From Opportunity Where id = :mySourceId];
            System.debug(whoTo);
            sender.name = whoTo.Third_Party_Name__c;
            sender.eAddress = whoTo.Third_Party_Email__c;
            sender.role = 'Signer 1';
            readyToProcess = true;

            templateInfo.put('Source_Reference', (String) mySourceId); // + '~Opportunity'
            templateInfo.put('UUID', dfsle.UUID.tryparse(settingsDocusignTemplate.get(sourceName).Template_ID__c));
            templateInfo.put('name', settingsDocusignTemplate.get(sourceName).Template_Name__c);
        }
        when else {
            throw new CustomException('Unknow object type not accounted for.  Please contact your System Administrator.');
        }
    }

    System.debug('Start the envelope build');
    System.debug(readyToProcess + '/' + (dfsle.UUID) templateInfo.get('UUID'));
    if (readyToProcess && (dfsle.UUID) templateInfo.get('UUID') != null) {
        myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(new dfsle.Entity(mySourceId));

        //use the Recipient.fromSource method to create the Recipient
        dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(sender.name, // Recipient name
                                                                 sender.eAddress, // Recipient email
                                                                 null, //Optional phone number
                                                                 sender.role, //Role Name. Specify the exact role name from template
                                                                 null); //source object for the Recipient - new dfsle.Entity(mySourceId)
        //add Recipient to the Envelope
        myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });

        //add email detail for the envelope
        myEnvelope = myEnvelope.withEmail(settingsDocusignTemplate.get(sourceName).email_subject__c, settingsDocusignTemplate.get(sourceName).email_body__c);

        //Could provide automatic notifications as well based off of criteria
        final boolean dfsle_reminder = settingsDocusignTemplate.get(sourceName).reminder__c;
        final integer dfsle_remindAfterDays = Integer.valueOf(settingsDocusignTemplate.get(sourceName).remindAfterDays__c); //wait before sending reminder
        final integer dfsle_reminderFrequencyDays = Integer.valueOf(settingsDocusignTemplate.get(sourceName).reminderFrequencyDays__c); //days between reminders
        final boolean dfsle_expires = settingsDocusignTemplate.get(sourceName).expires__c; //does the env expire
        final integer dfsle_expiresAfterDays = Integer.valueOf(settingsDocusignTemplate.get(sourceName).expiresAfterDays__c); //number of days be env expires
        final integer dfsle_expireWarnDays = Integer.valueOf(settingsDocusignTemplate.get(sourceName).expireWarnDays__c); //warning days before env expires 
        final boolean dfsle_updateChatter = false; //do we update chatter with updates; would have to relate the env to a contact
        dfsle.Notifications reminderNotifications = new dfsle.Notifications(dfsle_reminder, dfsle_remindAfterDays, dfsle_reminderFrequencyDays, dfsle_expires, dfsle_expiresAfterDays, dfsle_expireWarnDays, dfsle_updateChatter);

        //Assign the reminder notifications to the envelope
        myEnvelope = myEnvelope.withnotifications(reminderNotifications);

        //create a new document for the Envelope
        dfsle.Document myDocument = dfsle.Document.fromTemplate((dfsle.UUID) templateInfo.get('UUID'), // templateId in dfsle.UUID format
        (String) templateInfo.get('name')); // name of the template

        //add document to the Envelope
        myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument });

        //populate the custom fields on the Envelope
        List<dfsle.CustomField> myCustomFields = new List<dfsle.CustomField>();
        myCustomFields.add(new dfsle.CustomField('text', 'DSFSSourceObjectId', (String) templateInfo.get('Source_Reference'), null, false, true));
-->     myCustomFields.add(new dfsle.CustomField('text', '##SFOpportunity', (String) templateInfo.get('Source_Reference'), null, false, true));
        myEnvelope = myEnvelope.withCustomFields(myCustomFields);

        if (methodShipEnvelope(myEnvelope)) {

            switch on sourceName {
                //when 'Lead' {
                ////nothing to update yet
                //}
                when 'Opportunity' {
                    Opportunity updateOpp = new Opportunity();
                    updateOpp.id = mySourceId;
                    updateopp.Certification_Status__c = 'Requested';
                    updateopp.Third_Party_Sent_Date__c = Date.today();
                    updateopp.Send_3rd_Party_Verification_Docusign__c = false;
                    update updateOpp;
                }
                //Add any new sources here for follow up
            }
        }
    } else {
        if ((dfsle.UUID) templateInfo.get('UUID') == null) {
            throw new CustomException('A valid Docusign Template was not found. Please contact YPO help desk services to resolve.');
        } else {
            throw new CustomException('The sourceId provided was not for a currently configured object. Please contact YPO help desk services to resolve.');
        }
    }
}

Is this something I somehow need to update myself? The documentation from Docusign did not seem to support this; the assumption that this was taken care of by Docusigns side.

Reviewed the Docusign Status object and found that the status is being loaded, but the Opportunity reference field is not being populated even though I provided that information via the CustomFields.

Tried the following with no change in behavior;

templateInfo.put('Source_Reference', (String) mySourceId + '~Opportunity');
templateInfo.put('Source_Reference', (String) mySourceId + '~Opportunity__c');
templateInfo.put('Source_Reference', (String) mySourceId);

Template merges with the information from the opportunity just fine, but the object reference Id is not being propagated on the Docusign Status object dsfs__Opportunity__c field.

Update after conferring with Docusign Support:

new dfsle.CustomField ('text', '##SFOpportunity', (String) myOpportunity.Id, null, false, false);

This solved the issue!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...