sudhangi

Create Package from Template

0 votes
Hi, I have a requirement where I have a template with placeholders for signers. I need to create a new package from this template and replace the signer Placeholders with actual signer info. I referred to the CreatePackageFromTemplateWithReplacingPlaceholderExample but the problem I face is that instead of replacing the existing placeholder it creates a new signer for the package. My requirement will have 2 or more signers so I have to loop through a MAP to get all the signer info. Here is a sample of my code:
public class CreatePackageFromTemplateController {
	Void PackageFromTemplate(Map templateData) {
		SignerBuilder signer;

		String successMessage;
		
		String tempIdString = templateData.getAt("templateId");	
		PackageId tempPackageId = new PackageId(tempIdString);
		
		
		EslClient dssEslClient(/*this will have my URL and API key*/);

		/*Create the Package.*/
		PackageBuilder packageFromTemplate = newPackageNamed(templateData.packageName);
		packageFromTemplate.withSenderInfo(SenderInfoBuilder.newSenderInfo(templateData.senderEmail));

		def signersArray = templateData.signers;

		for (int j = 0; j 

Reply to: Create Package from Template

0 votes
Hi Sudhangi, Did you create your template through the ui or programmatically using the sdk?
Haris Haidary OneSpan Technical Consultant

Reply to: Create Package from Template

0 votes
I created the template through the UI Thanks, Sudhangi

Reply to: Create Package from Template

0 votes
Then you will need to retrieve the id of the placeholders first. Because when you create templates from the UI, eSignLive assigns randomly generated ids. It is not the same as the placeholder name. You could retrieve the placeholder ids this way:
PackageId packageId = new PackageId("ISwwFvZcAJaVGl0rptNxkPA-U6Q="); //id of your template
		
DocumentPackage pack = eslClient.getPackageService().getPackage(packageId);
		
List placeholders = pack.getPlaceholders();
		
for (Signer placeholder : placeholders) {
         System.out.println(placeholder.getId());
}
Once you have the ids, you can do:
.replacing(new Placeholder(PLACEHOLDER_ID))
Haris Haidary OneSpan Technical Consultant

Reply to: Create Package from Template

0 votes
Awesome! That works. Thanks, Sudhangi

Reply to: Create Package from Template

0 votes
Good to hear :)
Haris Haidary OneSpan Technical Consultant

Reply to: Create Package from Template

0 votes
I created a template through the UI. How do I then get the package id to retrieve the template? My goal is to take this template as a starting point for further tweaking.

Reply to: Create Package from Template

0 votes
You can either retrieve it from the URL by logging to your eSignLive account and browsing to your template or you can retrieve it programmatically:
		int index = 1;
		
		Page templates = eslClient.getPackageService().getTemplates(new PageRequest(index, 50));
		
		while (templates.getNumberOfElements() > 0){
			
			for (DocumentPackage template : templates){
				System.out.println(template.getName() + " " + template.getId());
				index++;
			}
			
			templates = eslClient.getPackageService().getTemplates(new PageRequest(index, 50));
		}
Haris Haidary OneSpan Technical Consultant

Reply to: Create Package from Template

0 votes
Thank you!

Reply to: Create Package from Template

0 votes
Wouldn't it be easier just to edit the json package template file in a text editor such as NotePad++?

Reply to: Create Package from Template

0 votes
There's lots of different ways you can go about it. The only reason I gave you a solution with the Java SDK is because the post is in the Java SDK section =]. If you want to update your template through the REST API, you would make a PUT request to "https://sandbox.esignlive.com/api/packages/{templateId}" with your updated json payload, if you're testing on sandbox for example.
Haris Haidary OneSpan Technical Consultant

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