amunjal

Allowing signer to upload a signature through apex sdk

0 votes

HI Team,

How can we allow a particular signer to upload a signature file into the agreement?

 

I know how to do it from UI but need to do it using salesforce apex code. Right now we are just adding the role as below.

Image removed.

 


Approved Answer

Reply to: Allowing signer to upload a signature through apex sdk

0 votes

Hi Duo,

I tried that too yesterday, it gives an internal error. Here is the code.

 

pkg = sdk.getPackage(packageId);

    for(OneSpanAPIObjects.Document doc : pkg.documents){

        for(OneSpanAPIObjects.Approval aprvl : doc.approvals){

            if(fileSignerRoleId==aprvl.role) {

                aprvl.fromFile=true;

                sdk.updateApproval(packageId, doc.Id, aprvl.id, aprvl);

            }

        }

     }

Package ID: 7DnYwrl91MyzxyFQo--RbngRLNs=
User: [email protected]


Reply to: Allowing signer to upload a signature through apex sdk

0 votes

Hi amunjal,

 

Thanks for your post! It's actually supported by APEX SDK to request signer attachment, you can refer to the Manager Signer's Attachment guide for more detailed information.

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Allowing signer to upload a signature through apex sdk

0 votes

Hi Duo,

 

Appreciate your response, but the link you shared is to add documents to transaction.

I am asking to add a configuration so we allow user to upload signature file while signing rather than drawing the signature. How do we do that via code?

On User Interface: you click on signature block and toggle "from file".

Thanks

Akshay


Reply to: Allowing signer to upload a signature through apex sdk

0 votes

Hi Akshay,

 

Thanks for the explanation, I see what you meant now.

You can find more details about the "Upload image as signature" feature from this blog: https://www.onespan.com/blog/onespan-sign-developer-uploading-image-signature

It's not part of the APEX sdk modelling, hence I believe the first step is to extend the SDK:
(1)OneSpanAPIObjects.cls > starting from line 51 > add an additional field "fromFile"

public class Approval

{

public Boolean fromFile;

public DateTime accepted;

public String data;

public List<Field> fields;

public String id;

public String name;

public String role;

public DateTime signed;

public Approval(){}

......

}

(2)Every time when placing the signature > make sure the signature field type is "SIGNATURE", subtype is "CAPTURE", and fromFile is true
    OneSpanAPIObjects.Field field = new OneSpanAPIObjects.Field();
    field.left = 208;
    field.width = 200;
    field.height = 50;
    field.top = 518;
    field.page = 0;
    field.subtype = 'CAPTURE';
    field.type = 'SIGNATURE';

        
    List<OneSpanAPIObjects.Field> fields = new List<OneSpanAPIObjects.Field>();
    fields.add(field);
         
    OneSpanAPIObjects.Approval approval = new OneSpanAPIObjects.Approval();
    approval.fields = fields;
    approval.role = roleId;

    approval.fromFile = true;


         
    String signatureResponse = sdk.addSignature(packageId, 'document1', approval);

 

Unfortunately that I don't currently have a SFDC account by hand, if you don't mind please go ahead with these changes and let me know if this works for you.

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Allowing signer to upload a signature through apex sdk

0 votes

HI Dua, it does not work. This is what i tried.

Even after updating the package and setting fromFile=true. it does not update on package.

    pkg = sdk.getPackage(packageId);

    for(OneSpanAPIObjects.Document doc : pkg.documents){

        for(OneSpanAPIObjects.Approval aprvl : doc.approvals){

            if(fileSignerRoleId==aprvl.role) aprvl.fromFile=true;

        }

     }

sdk.updatePackage(pkg, packageId);


Reply to: Allowing signer to upload a signature through apex sdk

0 votes

Hi Akshay,

 

If you are updating existing signatures, sdk.updatePackage() is not sufficient as it only updates package level attributes (e.g. package name, package status). To update each signatures, use sdk.updateApproval() function instead:
 

    pkg = sdk.getPackage(packageId);

    for(OneSpanAPIObjects.Document doc : pkg.documents){

        for(OneSpanAPIObjects.Approval aprvl : doc.approvals){

            if(fileSignerRoleId==aprvl.role) {

                 aprvl.fromFile=true;

                 sdk.updateApproval(packageId, doc.id, aprvl.id, aprvl);

           }

        }

     }

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Allowing signer to upload a signature through apex sdk

0 votes

Hi Akshay,

 

Thanks for the information! I saw that your package is currently in SENT status. Just wondering that did you first set the status as DRAFT before updating the approval?

sdk.setStatus(packageId, OneSpanAPIObjects.PackageStatus.DRAFT);

pkg = sdk.getPackage(packageId);

......

 

sdk.setStatus(packageId, OneSpanAPIObjects.PackageStatus.SENT);

 

If that still doesn't help, could you recreate a new package with the signature fromFile set as true?

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Allowing signer to upload a signature through apex sdk

0 votes

Again Error is thrown even after making it as draft.

OneSpanRESTAPIHelper.OneSpanRestAPIHelperException: Error creating OneSpan signer: 500 - Internal Server Error - {"messageKey":"error.internal.default","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.","code":500,"name":"Unhandled Server Error"}

 

I cannot create a new package with fromFile=true. Reason being, we add our tags to the document itself and send for package generation. Tags do not have any attribute to mark it from file.

{{esl:Signer1:Capture:Size(120,30)}}

Let me know what can be done in this case.


Reply to: Allowing signer to upload a signature through apex sdk

0 votes

I was able to update it using below code.

                    pkg = sdk.getPackage(packageId);

                    for(OneSpanAPIObjects.Document doc : pkg.documents){

                        if((String.valueOf(fileId)).equalsIgnoreCase(doc.id)){

//fileid is the document you used to generate the onespan package.

//if you try changing it for default-consent document, it will give error

                            for(OneSpanAPIObjects.Approval aprvl : doc.approvals){

                                if(signerRoleId==aprvl.role) {

                                    aprvl.fromFile=true;

                                    sdk.updateApproval(packageId, doc.Id, aprvl.id, aprvl);

                                }

                            }

                        }

                    }


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