Create a transaction from template + update fields
Thursday, January 7, 2021 at 04:59pmI created a template using the Web UI, where i added a "Signer1" placeholder along with some textboxes and checkboxes. I created a package from this template using this guide:
https://community.onespan.com/documentation/onespan-sign/guides/feature-guides/developer/creating-transaction-template
Now I'm looking to update these textboxes and checkboxesn with data programatically using the SDK before it is sent for signing. Can you provide some guidance on how to do this?
Reply to: Create a transaction from template + update fields
Friday, January 8, 2021 at 09:43amHi Carlos,
To update multiple fields with fewest number of outgoing APIs, you may want to assign all fields to one signature, and update all fields under the signature in bulk, with function:
eslClient.getApprovalService().modifySignature(DocumentPackage sdkPackage, String documentId, Signature signature)
Below is a code snippet using this function:
EslClient eslClient = new EslClient(API_KEY, API_URL);
DocumentPackage newPackage = PackageBuilder.newPackageNamed("package created from template")
.describedAs("package description")
.withEmailMessage("Please sign ASAP!")
.withSigner(SignerBuilder.newSignerWithEmail("[email protected]")
.withFirstName("John")
.withLastName("Smith")
.replacing(new Placeholder("c2305aa3-2046-4a29-a567-861449ac928c")))
.build();
PackageId packageId = eslClient.getTemplateService().createPackageFromTemplate(new PackageId("epH3WiDy7PrsTU59SMFXxGwjYw8="), newPackage);
System.out.println(packageId);
//field name : value pair
Map<String, String> fieldNameValuePair = new HashMap<String,String>(){{
put("textfield1","value1");
put("textfield2","value2");
put("checkbox1","X");
}};
DocumentPackage package1 = eslClient.getPackage(packageId);
//assume the target document's name is Document1
Document document = package1.getDocument("Document1");
for (Signature signature : document.getSignatures()) {
//assume the target signature's name is signature1
if(signature.getName().equals("signature1")) {
for (Field field : signature.getFields()) {
if(fieldNameValuePair.containsKey(field.getName())) {
field.setValue(fieldNameValuePair.get(field.getName()));
}
}
eslClient.getApprovalService().modifySignature(package1, document.getId().getId(), signature);
}
}
Duo
Reply to: Hi Carlos, To update…
Monday, January 11, 2021 at 12:19pmWorks great. Thanks!
Reply to: Hi Carlos, To update…
Friday, January 22, 2021 at 09:52amHi OneSpan Support,
We have business scenario where we create a package with 1 (or more signers) from a template. The request will include customs fields and labels for the signers. In addition, there will be a reviewer who needs to read the documents including the custom fields and labels. The reviewer does not sign the documents.
In the code, how can we create a reviewer who can read the document including the custom fields, but does not need to sign?
Thanks,
Carlos
Reply to: Create a transaction from template + update fields
Tuesday, February 16, 2021 at 03:43pmWould you be able to provide an example using the .NET SDK? What I see within that SDK does not completely line up with what you have shown. E.g. I do not see a ModifySignature method.
Thanks
Reply to: Would you be able to provide…
Tuesday, February 16, 2021 at 04:21pmHi rumfords,
Here you go:
EslClient eslClient = new EslClient(apiKey, apiUrl);
DocumentPackage newPackage = PackageBuilder.NewPackageNamed("package created from template")
.DescribedAs("package description")
.WithEmailMessage("Please sign ASAP!")
.WithSigner(SignerBuilder.NewSignerWithEmail("[email protected]")
.WithFirstName("John")
.WithLastName("Smith")
.Replacing(new Placeholder("c2305aa3-2046-4a29-a567-861449ac928c")))
.Build();
PackageId packageId = eslClient.CreatePackageFromTemplate(new PackageId("epH3WiDy7PrsTU59SMFXxGwjYw8="), newPackage);
Debug.WriteLine($"package id: {packageId}");
//field name : value pair
var fieldNameValuePair = new Dictionary<string, string>()
{
{"textfield1","value1" },
{"textfield2", "value2" },
{"checkbox1", "X" }
};
DocumentPackage package1 = eslClient.GetPackage(packageId);
//assume the target document's name is Document1
Document document = package1.GetDocument("Document1");
foreach (var signature in document.Signatures) {
//assume the target signature's id is xY4uEr6vniU2
if (signature.Id.Id == "xY4uEr6vniU2") {
foreach (var field in signature.Fields) {
if(fieldNameValuePair.ContainsKey(field.Name)) {
field.Value = fieldNameValuePair[field.Name];
}
}
eslClient.ApprovalService.ModifyApproval(package1, document.Id, signature);
break;
}
}
Duo
Reply to: Hi OneSpan Support, We have…
Tuesday, February 16, 2021 at 04:42pmHi Carlos,
Sorry for the late reply as I didn't receive a notification for your latest post.
Per your question:
#1 Not sure if you already knew that the Custom fields are only available for senders who has OneSpan Sign account, it offers you the ability to add supplementary information to your sender profiles in addition to the out-of-the-box fields like “title”, “company”. Kindly refer to my blogs for more information:
https://www.onespan.com/blog/onespan-sign-developer-custom-fields
https://www.onespan.com/blog/onespan-sign-developer-custom-fields-part-2
#2 In OneSpan Sign, if you didn't assign any signature to a recipient, then this recipient is a reviewer. However, I'm afraid it won't fit your use case:
-reviewer isn't involved into the signing process, so let's say the reviewer has a signing order of 1, it won't block the signing process and will directly forward the signing email to the next recipient
-reviewer, or other signers, won't be able to see the field values until the actual signer signed and stamped the value to the PDF.
So based on the foregoing, I would suggest:
-either you can leave the transaction in DRAFT status, build a designer page link (with a minimal looking customization, so it's more of a preview page than a designer). You can either embed the designer URL into your own application, or send the link by your own method - designer link is valid for 30 minutes.
Refer to my blog series for more information:
https://www.onespan.com/blog/onespan-sign-developer-designer-customization-and-integration-part-1
https://www.onespan.com/blog/onespan-sign-developer-designer-customization-and-integration-part-2
-or you can associate all the fields to the reviewer and have reviewer sign first - you can reduce the signature size to (0,0) so it won't be visible, however a certificate will still be sealed into the PDF.
Duo
Reply to: Create a transaction from template + update fields
Wednesday, February 17, 2021 at 07:57amThank you for the .NET example. Can you tell me where I would find the signature ID (e.g. "xY4uEr6vniU2" in your example)? Thanks.
Reply to: Thank you for the .NET…
Wednesday, February 17, 2021 at 12:10pmIf you can supply me (1)the environment you are developing with (2)the template ID (3)the signature name, I would check with support team for the signature ID. The reason why I used signature ID instead of name is because seems it's a bug in .NET SDK that the signature name won't be converted from API modelling to SDK modelling and always be null. I would also like to fill in a support ticket on your behalf reporting this if you preferred.
Duo
Reply to: Create a transaction from template + update fields
Wednesday, February 17, 2021 at 12:42pmI can figure out the signature ID that I need right now by checking it in my code at a breakpoint, but this isn't the ideal way to figure out what it is. Neither is checking with the support team each time. So yes, we would appreciate a support ticket for this as we'll require a long term solution where we can determine things via the OneSpan GUI. Thanks, Steve
Reply to: Hi Carlos, Sorry for the…
Wednesday, February 17, 2021 at 04:19pmThanks Duo.
Really appreciate your help with this.