mbilensky | Posts: 52

Cloning a Layout

0 votes
Hi, I'm having some issues when trying to clone/copy an existing layout in order to modify the signatures without affecting the original layout. I've attempted to call createLayout method in layout service on the original to recreate, but while this does create a copy, it also deletes the original layout. I currently have a workaround by creating a new package and copying over all the data from the original layout, but feels like there's a better way to accomplish this. Is there a recommended way to copy layouts? Thanks in advance, -Mitch

Approved Answer
mwilliams | Posts: 957

Reply to: Cloning a Layout

1 votes
This should do it. Let me know if you have issues.
DocumentPackage myLayout = eslClient.getLayoutService().getLayouts(Direction.DESCENDING, new PageRequest(1,50)).get(0);  //Just grabbing a layout
myLayout.setName("Some Different Name"); //this is the step that is necessary to not overwrite the existing one
//TODO: Whatever changes you want to make
eslClient.getLayoutService().createLayout(myLayout);

mwilliams | Posts: 957

Reply to: Cloning a Layout

1 votes
I've never tried to do this. Let me take a look into it and get back to you.

mbilensky | Posts: 52

Reply to: Cloning a Layout

0 votes
Thanks! This is just what I needed

mwilliams | Posts: 957

Reply to: Cloning a Layout

0 votes
Great! Glad I could help! :)

mbilensky | Posts: 52

Reply to: Cloning a Layout

0 votes
Having an issue using the above code for one specific layout. While this code has been working most of the time I ran into an issue when attempting to create a copy of one specific layout. An exception keeps being thrown stating that there are multiple entries with the same key for a field. I’ve looked through the properties of the layout and found a text field for a signature that has the id that the exception states there are multiple entries for, but no other fields with the same id. The same call is being done with identical layouts without any exceptions being thrown and is working as intended. I’ve been unable to recreate the issue outside of this one specific layout and wondering if you could provide any further information that could help. Approximate Code being used:
String layoutId = “NljTbsDDTYygDj6vXvMzN3Kszio=”
DocumentPackage layout = eslClient.getPackage(new PackageId(layoutId));
layout.setName(layout.getName() + “-1”);
String clonedLayoutId = eslClient.getLayoutService().createLayout(layout);
layout = eslClient.getPackage(new PackageId(clonedLayoutId));
Exception being thrown:
Caused by: com.silanis.esl.sdk.internal.EslServerException: Could not create layout. Exception: HTTP POST on URI https://sandbox.esignlive.com/api/layouts resulted in response with status code: [500, Internal Server Error]. Optional details: {"messageKey":"error.internal.default","technical":"Multiple entries with same key: MF84tvhX2NsV=com.silanis.esl.api.model.Field@31a655ed and MF84tvhX2NsV=com.silanis.esl.api.model.Field@18c0f02f","code":500,"message":"Unexpected error. We apologize for any inconvenience this may have caused you, please try again. If the problem persists, please contact our support team.","name":"Unhandled Server Error"}
	at com.silanis.esl.sdk.service.LayoutService.createLayout(LayoutService.java:55)
I can provide the API Key and layout id being used if needed Thanks in advance, Mitch

mwilliams | Posts: 957

Reply to: Cloning a Layout

0 votes
Hey Mitch, I'm sending you an email to the email address registered in the community to requrest more information.

mwilliams | Posts: 957

Reply to: Cloning a Layout

0 votes
If you look at the JSON for the layout, there are two fields with the same ID (MF84tvhX2NsV). One is a signature and one is a text field. I'm not really sure how that passed creation into the first layout, but it did. This is the signature for the role"EmergencyContact3" and the associated TEXTFIELD. If this conflict is resolved, the cloning should work as expected.

mbilensky | Posts: 52

Reply to: Cloning a Layout

0 votes
That looks whats causing the issue, but I'm now more concerned on how the layout got into this state in the first place. Is this a case of id collision? Is there any way to protect against this in the future or is this just a random chance event?

mwilliams | Posts: 957

Reply to: Cloning a Layout

0 votes
How was the layout originally created? If from a package, how was this package originally created?

mbilensky | Posts: 52

Reply to: Cloning a Layout

0 votes
This layout specifically was cloned using the same code as above and then had the layout designer window opened where the fields were added, and the original layout was created using this workflow except for adding placeholders instead of signers and adding signatures through the layout designer window instead of being added through the sdk.

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