Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Im trying to create a Signature Pad for Mobile View

Nitesh A
Tera Expert

For that i have created UI action on custom table.
and triggered UI Page "wo_accept_signature_mobile" but im unable to understand the process flow of this UI Page
and onClick of UI Page Button

"<button id='acceptSignature' onclick="return onAcceptSignature();" class="btn btn-primary">${gs.getMessage('Accept')}</button>"

there is Function "return onAcceptSignature();"

im unable to understand the execution of this function where it is located.

So please can anybody help me understand how does this work?

6 REPLIES 6

NEO ANDERSON
Kilo Contributor

Nitesh, were you able to find where this function onAcceptSignature() is located. We're also struggling with the same. Many thanks for your help.

Tom C1
Tera Expert

I know this is a very old post but I was desperately trying to find the same thing and I finally did, I'm hoping this helps someone in the future. The function but can be seen in:

https://<instance_name>.service-now.com/scripts/wo_signature_pad.jsx

and looks like:

function onAcceptSignature() {
    var sigPad = $j('.sigPad').signaturePad();
    var ajax = new GlideAjax('com.snc.signaturepad.SignatureProcessor');
    var isImage = gel('sysparm_draw_only') && gel('sysparm_draw_only').value == 'true' || $j('.drawIt').hasClass("active");
    var isSigneeNameReq = gel('sysparm_signeename_required') && gel('sysparm_signeename_required').value == 'true' && gel('signee_name') && gel('signee_name').value && gel('signee_name').value != '';
    if (isSigneeNameReq) {
        var signee_name = gel('signee_name').value.replace(/^\s+|\s+$/g, '');
        isSigneeNameReq = isSigneeNameReq && signee_name != '';
    }
    var submit = true;
    var tableName = '';
    if (gel('table_name') && gel('table_name').value)
        tableName = gel('table_name').value;
    var documentId = '';
    if (gel('document_id') && gel('document_id').value)
        documentId = gel('document_id').value;
    if (isImage) {
        clearErrors();
        if (sigPad.getSignature().length > 0 && isSigneeNameReq) {
            gel('acceptSignature').disabled = true;
            gel('cancelSignature').disabled = true;
            var png = sigPad.getSignatureImage();
            var signed_name = gel('signee_name').value;
            var params = {
                'action': 'acceptSignatureImage',
                'table': tableName,
                'document': documentId,
                'image': png,
                'data': sigPad.getSignatureString(),
                'signed_name': signed_name
            };
            ajax.getXML(acceptSignatureCallBack, params);
        } else {
            onFormDrawError();
            submit = false;
        }
    } else if (!isImage) {
        if (sigPad.validateForm()) {
            var signed_name = $j('.signed_name').val();
            var parameters = {
                'action': 'acceptSignatureName',
                'table': tableName,
                'document': documentId,
                'signed_name': '<p><font size="7" face="journal">' + signed_name + '</font></p>'
            };
            ajax.getXML(acceptSignatureCallBack, parameters);
        } else
            submit = false;
    }
    doSubmit(submit);
    return false;
}
function acceptSignatureCallBack(response) {
    var answer = response.responseXML && response.responseXML.firstChild.textContent;
    var gf = new GlideForm();
    if (answer == "Signature accepted") {
        $j('#acceptSignature').closest('form').submit();
    }
    else
        gf.addErrorMessage("There was an error with the processing of the signature");
}
function onCancelSignature() {
    doSubmit(false);
    return false;
}

JW22
Tera Contributor

Hey Tom,

 

I'm looking to similarly implement a signature pad in our mobile app, and just came across your post! Looks very helpful! Can you please elaborate how you implemented this? I tried to access scripts/wo_signature_pad.jsx but was met with an error message. 

 

Thank you!

wo_signature_pad.jsx comes with the Field Service - Signature Pad [com.snc.wo_signature_pad] plugin