OneSpan SDK to retrieve
Wednesday, February 28, 2024 at 04:41pmWe're trying to generate the package using template. Templates are created in sandbox.esignlive.com. While generating the package we're receiving below exception, OneSpanRESTAPIHelper.OneSpanRestAPIHelperException: Error updating package with OneSpan: 400 - Bad Request - {"messageKey":"error.validation.packageActivation.unassignedRole","message":"There is a role with no signer.","code":400,"name":"Validation Error"}
We're executing below code,
OneSpanSDK sdk = new OneSpanSDK();
//step1: create a transaction out of the template OneSpanAPIObjects.Package_x pkg = new OneSpanAPIObjects.Package_x();
pkg.name = 'TEST';
pkg.description = 'TEST';
String placeholder1Id = 'hJNKqQncmYMQ';
OneSpanAPIObjects.Role role1 = new OneSpanAPIObjects.Role(); OneSpanAPIObjects.Signer signer1 = new OneSpanAPIObjects.Signer();
signer1.firstName = 'Mr.';
signer1.lastName = 'Ankit';
signer1.email = '[email protected]'; signer1.id = placeholder1Id;
role1.signers = new List<OneSpanAPIObjects.Signer>{signer1};
String roleId = role1.Id;
role1.id = placeholder1Id;
pkg.roles = new List<OneSpanAPIObjects.Role>{role1};
pkg = sdk.helper.createPackageFromTemplate(pkg,'KpUJgwfBRmR7yX4MsMaJtRFtbzU=');
//step2: update label fields
OneSpanAPIObjects.Package_x pack = sdk.getPackage(pkg.id);
Map<String, String> labelFieldValue = new Map<String, String>{ 'LjIO5N5HRJUK' => 'Ankit Thakkar' };
for(OneSpanAPIObjects.Document document: pack.documents){ for(OneSpanAPIObjects.Approval approval: document.approvals){ Boolean isUpdate = false; for(OneSpanAPIObjects.Field field: approval.fields){ system.debug('--> '+field.Id); if(labelFieldValue.containsKey(field.Id)){ isUpdate = true; field.value = labelFieldValue.get(field.Id); } } if(isUpdate){ sdk.updateApproval(pkg.id, document.id, approval.id, approval); } } } //step 3:send the transaction pack.status = OneSpanAPIObjects.PackageStatus.SENT; sdk.updatePackage(pack, pack.id);
Reply to: OneSpan SDK to retrieve
Wednesday, February 28, 2024 at 04:54pmHi Ankit,
Thanks for your post! For the given template "KpUJgwfBRmR7yX4MsMaJtRFtbzU=", your placeholder ID should be "bf2d8155-f5e4-4d32-b50e-e64517d1022b", use it as the role ID:
String placeholder1Id = 'bf2d8155-f5e4-4d32-b50e-e64517d1022b';
Duo
Reply to: OneSpan SDK to retrieve
Wednesday, February 28, 2024 at 04:57pmHi Duo, Thank you for sharing the Role ID but how I can get it dynamically as we are dealing with 18 different templates?
Reply to: OneSpan SDK to retrieve
Thursday, February 29, 2024 at 08:44amHi Ankit,
Try using below logic to distinguish placeholder between regular signer:
OneSpanSDK sdk = new OneSpanSDK();
OneSpanAPIObjects.Package_x template = sdk.getPackage('ki1AjjsBc9O9bU2k8SFwL3y1i_0=');
List<OneSpanAPIObjects.Role> placeholders = new List<OneSpanAPIObjects.Role>();
for(OneSpanAPIObjects.Role role: template.roles){
if(role.signers.size() == 0){
placeholders.add(role);
System.debug('placeholder.id:' + role.id);
System.debug('placeholder.name:' + role.name);
}
}
Duo