Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Docusign Integration

Mauro Russo
Tera Contributor

Hello everyone, 

i've built the integration between Servicenow and Docusign in order to have digital signature for HR Documents. 

Now the issue that i'm facing is related to the fact that the document is attached on the HR Task, after attached it will trigger the docusign integration and the user signs the document but the signature is not mandatory. So the user needs to put the signature clicking on the icon. 

I would like to have the anchor tag pre-defined and mandatory in order to have already the correct position where the user will need to sign.

 

Any suggestions?

Thanks in advance

 

5 REPLIES 5

Mauro Russo
Tera Contributor

Hello, i have tried also to put the other anchor tags but seems not working. 

When the user sign the document only the anchor tag "sign-here" is working.

The script part in bold (please, refer to the script below) is not working but maybe i've missed something.

I put here the script that i've made in the action designer

 

SCRIPT:

 

(function execute(inputs, outputs) {
    outputs.api_version = new DocuSignUtils().getAPIVersion(inputs.sys_alias);
    inputs = new DocuSignUtils().trimStringInputs(inputs);
    var gr = new GlideRecordSecure('sys_attachment');
    gr.get(inputs.attachment)
    inputs.document_file_name = gr.file_name;
    if (inputs.document_file_name) {
        if (inputs.document_file_name.lastIndexOf('.') == -1)
            throw new Error("Missing file extension");
        outputs.document_type = inputs.document_file_name.substring(inputs.document_file_name.lastIndexOf('.') +
            1);
        outputs.email_subject = JSON.stringify(inputs.email_subject);
        outputs.document_name = inputs.document_name;
        outputs.email_body = JSON.stringify(inputs.email_body);
        if (inputs.envelope_expire_days) {
            outputs.envelope_expire_days =
                ", \"notification\": {\"expirations\": { \"expireEnabled\": \"true\", \"expireAfter\" : \" " +
                inputs.envelope_expire_days + "\"}}";
        }
        outputs.recipient_name = inputs.recipient_name;
        outputs.recipient_email = inputs.recipient_email;
        var gr = new GlideRecordSecure("sys_attachment");
        if (gr.get(inputs.attachment)) {
            var ga = new GlideSysAttachment();
            gr = new GlideRecordSecure("sys_attachment");
            gr.addQuery('sys_id', inputs.attachment);
            gr.query();
            if (gr.next())
                outputs.enc_data = ga.getContentBase64(gr);
        }
        if (!inputs.embedded_signing) {
            if (!inputs.recipient_email || !inputs.recipient_name)
                outputs.pre_status = "Either Recipient Email or Recipient Name has not been provided.";
        }
        if (inputs.embedded_signing) {
            if (gs.nil(inputs.user_record))
                throw new Error("Embedded Signing Recipient must be provided to use Embedded Signing");
            if (inputs.user_record_email && inputs.user_record_name && inputs.user_id) {
                //var recipients = new DocuSignUtils().sendSignatureUserEmbedded(inputs.user_record_name, inputs.user_record_email, inputs.user_id);
                var recipients = {
                    "recipients": {
                        "signers": [{
                            "name": inputs.user_record_name,
                            "email": inputs.user_record_email,
                            "recipientId": "1",
                            "clientUserId": inputs.user_id,
                          "tabs": {
                            "signHereTabs": [{
                              "anchorString": "sign-here",
                              "anchorXOffset": "1",
                              "anchorYOffset": "0",
                              "anchorIgnoreIfNotPresent": "true",
                              "anchorUnits": "inches" }],

                             
                          "textTabs": [{
                             "type": "text",
                            "anchorString": "text-here",
                            "anchorUnits": "inches",
                            "anchorXOffset": "10",
                            "anchorYOffset": "20",
                            "documentId": "1",
                            "pageNumber": "1",
                            "anchorIgnoreIfNotPresent": "true",
                            "tabLabel": "text-here",
                            "locked": "false"         
                }]
                          }
                        }]
                    }
                }
                outputs.recipients = JSON.stringify(recipients.recipients);
                outputs.recipient_name = inputs.user_record_name;
                outputs.recipient_email = inputs.user_record_email;
            } else
                outputs.pre_status =
                "User Record is not provided or the User Record is missing either the name, email or user ID.";
        }
        if (!inputs.embedded_signing){
            //var recipients = new DocuSignUtils().sendSignatureUserNotEmbedded(outputs.recipient_name, outputs.recipient_email);
         var recipients = {
                "recipients": {
                    "signers": [{
                        "name": outputs.recipient_name,
                        "email": outputs.recipient_email,
                        "recipientId": "1",
                      "tabs": { "signHereTabs": [{
                        "anchorString": "sign-here",
                        "anchorXOffset": "1",
                        "anchorYOffset": "0",
                        "anchorIgnoreIfNotPresent": "true",
                        "anchorUnits": "inches" }] },

   
                        "textTabs": [{
                             "type": "text",
                            "anchorString": "text-here",
                            "anchorUnits": "inches",
                            "anchorXOffset": "10",
                            "anchorYOffset": "20",
                            "documentId": "1",
                            "pageNumber": "1",
                            "anchorIgnoreIfNotPresent": "true",
                            "tabLabel": "text-here",
                            "locked": "false"
                        }]
                       

                          /* "recipientSignatureProviders": [{
                        "signatureProviderName": outputs.signature_type,
                              "signatureProviderOptions": {
                                "sms": inputs.recipient_mobile_number
                                }
                        }]*/
                    }]
                }
            }
        var cc_users = inputs.cc_users;
        var CCflag = false;
        recipients.recipients.carbonCopies = [];
        for (var i in cc_users) {
            if (cc_users[i].email && cc_users[i].name) {
                CCflag = true;
                var user = new DocuSignUtils().sendSignatureUserCC(cc_users[i]);
            }
            if (CCflag == true)
                recipients.recipients.carbonCopies.push(user);
        }
        outputs.recipients = JSON.stringify(recipients.recipients);
        outputs.recipient_name = inputs.recipient_name;
        outputs.recipient_email = inputs.recipient_email;
        }
    } else {
        throw new Error("Invalid Attachment");
    }
})(inputs, outputs);