pdemidoff | Posts: 4

Updating textField value when last signer signs the document.

0 votes
Hi, We need to send a document to one or more signers and then sign as a company (we are the last signer). Also, we need to write some info in the document at that moment. So, I added a textField in the document with no value when uploading / sending the document, and when we are signing the document as the last signer trying to change the value to the textField. It does not work. The code is something like this: Uploading / Sending the document
	DocumentBuilder documentBuilder = DocumentBuilder.newDocumentWithName(documentPackageName)
			.fromFile(file.getAbsolutePath())
			.enableExtraction()
			.withExtractionType(ExtractionType.TEXT_TAGS);
	documentBuilder = documentBuilder.withId("documentId")
		.withSignature(SignatureBuilder.signatureFor(senderEmail)
			.withId(new SignatureId("companySignature"))
			.withPositionAnchor(TextAnchorBuilder.newTextAnchor("SIGNATURE:")
				.withSize(150, 40)
				.withOffset(0, 10)
				.withCharacter(0)
				.withOccurence(0))
			.withField(FieldBuilder.textField()
				.withId(new FieldId("fieldId"))
				.withPositionAnchor(TextAnchorBuilder.newTextAnchor("TEXT:")
					.withSize(100, 40)
					.withOffset(30, 10)
					.withCharacter(0)
					.withOccurence(0))
				)
			);
	Document document = documentBuilder.build();
	eslClient.uploadDocument(document, packageId);
Signing the document
	// Change Package Status to DRAFT
	DocumentPackage documentPackage = eslClient.getPackage(packageId);
	documentPackage.setStatus(PackageStatus.DRAFT);
	eslClient.updatePackage(packageId, documentPackage);
	// Fill textField
	SignatureId signatureId = new SignatureId("companySignature");
	FieldId fieldId = new FieldId("fieldId");
	Field field = eslClient.getApprovalService().getField(packageId, "documentId", signatureId, fieldId);
	field.setValue("START DATE");
	eslClient.getApprovalService().updateField(packageId, "documentId", signatureId, field);
	// Return Package Status to SENT
	documentPackage.setStatus(PackageStatus.SENT);
	eslClient.updatePackage(packageId, documentPackage);
	// Sign Documents
	eslClient.signDocuments(packageId, sender.getEmail());
	// Mark Transaction as completed.
	PackageService packageService = eslClient.getPackageService();
	packageService.markComplete(packageId);
We would appreciate any suggestion. Thanks

Duo_Liang | Posts: 3776

Reply to: Updating textField value when last signer signs the document.

0 votes
Hi there, Thanks for the code snippet, it's very clear for me to reproduce the issue! The reason why the text field value didn't get changed is, you can't modify a document (including add/edit fields) once someone has started to sign it. Instead, you could use below API Call to update the field value, which is the actual AJAX Call sending out during signing ceremony:
https://sandbox.esignlive.com/packages/Yr7UHjmleteS9SOmd8arN5aR3R4%3D/documents/documentId/approvals/companySignature/fields/fieldId
There's no /api in the URL, so it's better not to add. Header:
Content-type: application/json
Authorization: Basic {your_api_key}
Payload:
{"value":"START DATE"}
There's no corresponding SDK function out of the box, so if you want, I can create some sample code for you. Hope this could help! Duo

pdemidoff | Posts: 4

Reply to: Updating textField value when last signer signs the document.

0 votes
Thanks Duo for your quick response. I will appreciate if you add a code sample. Regards, Pablo

Duo_Liang | Posts: 3776

Reply to: Updating textField value when last signer signs the document.

0 votes
Hey Pablo, See the code below:
	private void updateFieldValue(String packageId, String documentId, String signatureId, String fieldId,String newValue) {
			HttpURLConnection sourceConn = null;
			String url = API_URL.substring(0, API_URL.lastIndexOf("/api"))+"/packages/" + packageId + "/documents/" + documentId+"/approvals/" + signatureId + "/fields/" + fieldId;
			System.out.println(url);
			try {
				URL sourceClient = new URL(url);
				sourceConn = (HttpURLConnection) sourceClient.openConnection();
				sourceConn.setRequestProperty("Content-Type", "application/json");
				sourceConn.setRequestProperty("Authorization", "Basic " + API_KEY);
				sourceConn.setRequestMethod("POST");
				sourceConn.setDoOutput(true);
				sourceConn.setDoInput(true);
				
				String payload = String.format("{\"value\":\"%s\"}", newValue);
				System.out.println(payload);
				
				OutputStream os = sourceConn.getOutputStream();
				os.write(payload.getBytes());
				os.flush();
				os.close();

				int sourceResponseCode = ((HttpURLConnection) sourceConn).getResponseCode();

				Reader ir = sourceResponseCode == 200 ? new InputStreamReader(sourceConn.getInputStream())
						: new InputStreamReader(sourceConn.getErrorStream());
				BufferedReader in = new BufferedReader(ir);
				String inputLine;
				StringBuffer response = new StringBuffer();

				while ((inputLine = in.readLine()) != null) {
					response.append(inputLine);
				}

				in.close();

				if (sourceResponseCode != 200) {
					throw new EslException(response.toString());
				}
			} catch (Exception e) {
				throw new RuntimeException("Something went wrong when invoking API Call: POST " + url);
			} finally {
				if (sourceConn != null) {
					sourceConn.disconnect();
				}
			}
		}
And the attachment is the complete code I used for test. Duo

Attachments
pdemidoff | Posts: 4

Reply to: Updating textField value when last signer signs the document.

0 votes
Duo, Thank you so much. I will implement this method. Do I still need to change the package status to DRAFT before the change?. Pablo

Duo_Liang | Posts: 3776

Reply to: Updating textField value when last signer signs the document.

0 votes
Hey Pablo, In this case, you don't need to change the status to draft first, the function works when transaction was in SENT status. Duo

pdemidoff | Posts: 4

Reply to: Updating textField value when last signer signs the document.

0 votes
Hi Duo, It's not working. I am getting a sourceResponseCode 403. With message: {"code":403,"messageKey":"error.forbidden.signatureNotAssigned","message":"This signature is not assigned to you for signing.","name":"Access Denied"} Do I have to sign the document before updating the textField. For the last signer I have the signature block (click), a signing date and the text field. Also, can we continue this privately?. Regards, Pablo

Duo_Liang | Posts: 3776

Reply to: Updating textField value when last signer signs the document.

0 votes
Sure Pablo! I will reply to the email that you used to register your forum account. Duo

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off