簡體   English   中英

我們如何以編程方式添加公式選項卡以及使用java rest api客戶端在docusign中添加規則?

[英]How do we add Formula tabs programmatically and also a rule in docusign using java rest api client?

我正在嘗試添加公式選項卡,並嘗試在該公式選項卡上創建條件邏輯。 公式選項卡和創建規則類的類名是什么(調用它們)?

不知道哪個類調用這些方法。

    package com.docusign.controller.examples;

    import com.docusign.esign.api.TemplatesApi;
    import com.docusign.esign.client.ApiClient;
    import com.docusign.esign.client.ApiException;
    import com.docusign.esign.model.*;
    import com.sun.jersey.core.util.Base64;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.RequestMapping;
    import javax.servlet.http.HttpSession;
    import java.io.IOException;
    import java.util.Arrays;

    @Controller
    @RequestMapping("/eg008")
    public class EG008ControllerCreateTemplate extends EGController {

    @Autowired
    protected HttpSession session;

    @Override
    protected void addSpecialAttributes(ModelMap model) {
    }

    @Override
    protected String getEgName() {
        return "eg008";
    }

    @Override
    protected String getTitle() {
        return "Create a template";
    }

    @Override
    protected String getResponseTitle() {
        return "Template results";
    }

    @Override
    // ***DS.snippet.0.start
    protected EnvelopeDocumentsResult doWork(WorkArguments args, ModelMap 
   model,
                                             String accessToken, String 
    basePath) throws ApiException, IOException {
        // Data for this method
        // accessToken    (argument)
        // basePath       (argument)
        // config.appUrl  (url of the application itself)
        String accountId = args.getAccountId();
        String templateName = "Example Signer and CC template";


        // Step 1. list existing templates
        ApiClient apiClient = new ApiClient(basePath);
        apiClient.addDefaultHeader("Authorization", "Bearer " + accessToken);
        TemplatesApi templatesApi = new TemplatesApi(apiClient);
        TemplatesApi.ListTemplatesOptions options = templatesApi.new 
    ListTemplatesOptions();
        options.setSearchText(templateName);
        // get the results
        EnvelopeTemplateResults results = 
    templatesApi.listTemplates(accountId, options);

        // Step 2. process results. Template found?
        String templateId;
        String resultsTemplateName;
        boolean createdNewTemplate;
        if (Integer.parseInt(results.getResultSetSize()) > 0) {
            // Yes. Save the template id and name
            EnvelopeTemplateResult template = 
    results.getEnvelopeTemplates().get(0);
            templateId = template.getTemplateId();
            resultsTemplateName = template.getName();
            createdNewTemplate = false;
        } else {
            // No. Make a new template
            // Prepare request
            args.setTemplateName("Example Signer and CC template");
            EnvelopeTemplate templateReqObject = makeTemplate(args);
            // Call DocuSign
            TemplateSummary template = templatesApi.createTemplate(accountId, 
    templateReqObject);
            // process result
            templateId = template.getTemplateId();
            resultsTemplateName = template.getName();
            createdNewTemplate = true;
        }

        // Save templateId
        session.setAttribute("templateId", templateId);
        String msg = createdNewTemplate ?
                "The template has been created!" :
                "The template already exists in your account.";

        setMessage(msg + "<br/>Template name: " + resultsTemplateName + ", ID 
    " + templateId + ".");

        return null;
    }

    private EnvelopeTemplate makeTemplate(WorkArguments args) throws 
    IOException {
        // document 1 (pdf) has tag /sn1/
        //
        // The template has two recipient roles.
        // recipient 1 - signer
        // recipient 2 - cc
        // The template will be sent first to the signer.
        // After it is signed, a copy is sent to the cc person.
        // read file from a local directory
        // The reads could raise an exception if the file is not available!
        byte[] docPdfBytes = readFile("World_Wide_Corp_fields.pdf");
        // add the documents
        Document doc = new Document();
        String docB64 = new String(Base64.encode(docPdfBytes));
        doc.setDocumentBase64(docB64);
        doc.setName("Lorem Ipsum"); // can be different from actual file name
        doc.setFileExtension("pdf");
        doc.setDocumentId("1");

        // create a signer recipient to sign the document, identified by name 
    and email
        // We're setting the parameters via the object creation
        Signer signer1 = new Signer();
        signer1.setRoleName("signer");
        signer1.setRecipientId("1");
        signer1.setRoutingOrder("1");
        // routingOrder (lower means earlier) determines the order of 
    deliveries
        // to the recipients. Parallel routing order is supported by using 
    the
        // same integer as the order for two or more recipients.

        // create a cc recipient to receive a copy of the documents, 
    identified by name and email
        // We're setting the parameters via setters
        CarbonCopy cc1 = new CarbonCopy();
        cc1.setRoleName("cc");
        cc1.setRoutingOrder("2");
        cc1.setRecipientId("2");
        // Create fields using absolute positioning:
        SignHere signHere = new SignHere();
        signHere.setDocumentId("1");
        signHere.setPageNumber("1");
        signHere.setXPosition("191");
        signHere.setYPosition("148");

        Checkbox check1 = new Checkbox();
        check1.setDocumentId("1");
        check1.setPageNumber("1");
        check1.setXPosition("75");
        check1.setYPosition("417");
        check1.setTabLabel("ckAuthorization");


        Checkbox check2 = new Checkbox();
        check2.setDocumentId("1");
        check2.setPageNumber("1");
        check2.setXPosition("75");
        check2.setYPosition("447");
        check2.setTabLabel("ckAuthentication");

        Checkbox check3 = new Checkbox();
        check3.setDocumentId("1");
        check3.setPageNumber("1");
        check3.setXPosition("75");
        check3.setYPosition("478");
        check3.setTabLabel("ckAgreement");

        Checkbox check4 = new Checkbox();
        check4.setDocumentId("1");
        check4.setPageNumber("1");
        check4.setXPosition("75");
        check4.setYPosition("508");
        check4.setTabLabel("ckAcknowledgement");

        List list1 = new List();
        list1.setDocumentId("1");
        list1.setPageNumber("1");
        list1.setXPosition("142");
        list1.setYPosition("291");
        list1.setFont("helvetica");
        list1.setFontSize("size14");
        list1.setTabLabel("list");
        list1.setRequired("false");
        list1.setListItems(Arrays.asList(
                createListItem("Red"),
                createListItem("Orange"),
                createListItem("Yellow"),
                createListItem("Green"),
                createListItem("Blue"),
                createListItem("Indigo"),
                createListItem("Violet")
        ));
        // The SDK can't create a number tab at this time. Bug DCM-2732
        // Until it is fixed, use a text tab instead.
        //   , number = docusign.Number.constructFromObject({
        //         documentId: "1", pageNumber: "1", xPosition: "163", 
        yPosition: "260",
        //         font: "helvetica", fontSize: "size14", tabLabel: 
        "numbersOnly",
        //         height: "23", width: "84", required: "false"})
        Text textInsteadOfNumber = new Text();
        textInsteadOfNumber.setDocumentId("1");
        textInsteadOfNumber.setPageNumber("1");
        textInsteadOfNumber.setXPosition("153");
        textInsteadOfNumber.setYPosition("260");
        textInsteadOfNumber.setFont("helvetica");
        textInsteadOfNumber.setFontSize("size14");
        textInsteadOfNumber.setTabLabel("numbersOnly");
        textInsteadOfNumber.setHeight(23);
        textInsteadOfNumber.setWidth(84);
        textInsteadOfNumber.required("false");

        RadioGroup radioGroup = new RadioGroup();
        radioGroup.setDocumentId("1");
        radioGroup.setGroupName("radio1");

        radioGroup.setRadios(Arrays.asList(
                createRadio("white", "142"),
                createRadio("red", "74"),
                createRadio("blue", "220")
        ));

        Text text = new Text();
        text.setDocumentId("1");
        text.setPageNumber("1");
        text.setXPosition("153");
        text.setYPosition("230");
        text.setFont("helvetica");
        text.setFontSize("size14");
        text.setTabLabel("text");
        text.setHeight(23);
        text.setWidth(84);
        text.required("false");

        // Tabs are set per recipient / signer
        Tabs signer1Tabs = new Tabs();
        signer1Tabs.setCheckboxTabs(Arrays.asList(check1, check2, check3, 
        check4));
        signer1Tabs.setListTabs(Arrays.asList(list1));
        // numberTabs: [number],
        signer1Tabs.setRadioGroupTabs(Arrays.asList(radioGroup));

        signer1Tabs.setSignHereTabs(Arrays.asList(signHere));

        signer1Tabs.textTabs(Arrays.asList(text, textInsteadOfNumber));

        signer1.setTabs(signer1Tabs);

        // Add the recipients to the env object
        Recipients recipients = new Recipients();
        recipients.setSigners(Arrays.asList(signer1));
        recipients.setCarbonCopies(Arrays.asList(cc1));

        // create the envelope template definition object
        EnvelopeTemplateDefinition envelopeTemplateDefinition = new 
         EnvelopeTemplateDefinition();
        envelopeTemplateDefinition.setDescription("Example template created 
        via the API");
        envelopeTemplateDefinition.setName(args.getTemplateName());
        envelopeTemplateDefinition.setShared("false");

        // create the overall template definition
        EnvelopeTemplate template = new EnvelopeTemplate();
        // The order in the docs array determines the order in the env
        template.setDocuments(Arrays.asList(doc));
        template.setEmailSubject("Please sign this document");
        template.setEnvelopeTemplateDefinition(envelopeTemplateDefinition);
        template.setRecipients(recipients);
        template.setStatus("created");

        return template;
    }

    private ListItem createListItem(String color) {
        ListItem item = new ListItem();
        item.setText(color);
        item.setValue(color.toLowerCase());
        return item;*emphasized text*`enter code here`
    }

    private Radio createRadio(String value, String xPosition) {
        Radio radio = new Radio();
        radio.setPageNumber("1");
        radio.setValue(value);
        radio.setXPosition(xPosition);
        radio.setYPosition("384");
        radio.setRequired("false");
        return radio;
    }
    // ***DS.snippet.0.end
}

以編程方式創建的具有條件邏輯的模板。

我在C#中有一個例子,這有幫助嗎?

它創建三個數字選項卡,其中一個是復選框選項卡的條件子項。 公式選項卡將三個數字選項卡添加到一起。

        Checkbox checkbox = new Checkbox
        {
            TabLabel = "ToggleNumber3",
            Selected = "True",
            XPosition = "10",
            YPosition = "10",
            DocumentId = "1",
            PageNumber = "1",
        };

        Number number1 = new DocuSign.eSign.Model.Number
        {
            TabLabel = "Number1",
            Value = "1",
            RecipientId = "1",
            XPosition = "20",
            YPosition = "10",
            DocumentId = "1",
            PageNumber = "1",
        };

        Number number2 = new Number
        {
            TabLabel = "Number2",
            Value = "2",
            XPosition = "30",
            YPosition = "10",
            DocumentId = "1",
            PageNumber = "1",
        };

        Number number3 = new Number
        {

            TabLabel = "Number3",
            Value = "8",
            XPosition = "500",
            YPosition = "10",
            ConditionalParentLabel = "ToggleNumber3",
            ConditionalParentValue = "On",
            DocumentId = "1",
            PageNumber = "1",
        };

        FormulaTab additionFormula = new FormulaTab
        {
            TabLabel = "AdditionFormula",
            YPosition = "30",
            XPosition = "10",
            Formula = "[Number1] + [Number2] + [Number3]",
            DocumentId = "1",
            PageNumber = "1",
        };



        // Add the sign here tab array to the signer object.
        signer.Tabs = new Tabs
        {
            SignHereTabs = new List<SignHere>(signHereTabs),
            NumberTabs = new List<Number> { number1, number2, number3},
            FormulaTabs = new List<FormulaTab> { additionFormula },
            CheckboxTabs = new List<Checkbox> { checkbox },

        };

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM