Categories:

In OOB after esignature its capture signature but actual PDF did not marge with Signature

We need custom solution to achieve this issue.

Business Rule:

var templateAttachID = new HRTaskSignature().getTemplateID(current);
	if(templateAttachID){
		var signatureID = new HRTaskSignature().getSignature(current);
		if(signatureID){
			new HRTaskSignature().margePDF(current,templateAttachID,signatureID);
		}
	}

Script Include:

var HRTaskSignature = Class.create();
HRTaskSignature.prototype = {
    initialize: function() {},
    getTemplateID: function(current) {
        var hrDocument = current.sn_esign_esignature_configuration.managed_document;
        var grDocR = new GlideRecord('dms_document_revision');
        grDocR.addQuery('document', hrDocument);
        grDocR.addQuery('stage', 'published');
        grDocR.query();
        if (grDocR.next()) {
            var gratt = new GlideRecord('sys_attachment');
            gratt.addQuery('table_name', 'dms_document_revision');
            gratt.addQuery('table_sys_id', grDocR.sys_id);
            gratt.query();
            if (gratt.next()) {
                return gratt.sys_id;
            }
        }
    },
	getSignature : function (current){
		var grSignA = new GlideRecord('sn_esign_acknowledgement');
		grSignA.addQuery('document',current.sys_id);
		grSignA.orderByDesc('sys_created_on');
		grSignA.query();
		if(grSignA.next()){
			var gratt = new GlideRecord('sys_attachment');
            gratt.addQuery('table_name', 'signature_image');
            gratt.addQuery('table_sys_id', grSignA.signature.sys_id);
            gratt.query();
            if (gratt.next()) {
                return gratt.sys_id;
            }
		}
	},
    margePDF: function(current,temID,SignID) {
        var params = {
            fillablePdfSysId: temID,
            targetTableName: current.getTableName(),
            targetRecordSysId: current.getUniqueValue(),
            targetPdfName: current.sn_esign_esignature_configuration.name + '.pdf'
        };

        params.fieldMap = {
            /* company: 'Company X',
            employee: current.assigned_to.getDisplayValue(),
            ci: current.category.getDisplayValue(),
            brand: current.manufacturer.getDisplayName(),
            model: current.model_id.getDisplayValue(),
            date: String(new GlideDate().getByFormat('dd-MM-yyyy')) */
        };

        var signature = {
            pageNumber: 1,
            leftMargin: 35,
            topMargin: 350,
            boxWidth: 180,
            boxHeight: 180,
            attachmentImageSysId: SignID
        };

        var pdfSignRequestor = new sn_pdfgeneratorutils.PdfMergeSignRequestor();
        pdfSignRequestor.addSignatureMapping(signature.pageNumber, signature.leftMargin, signature.topMargin, signature.boxWidth, signature.boxHeight, signature.attachmentImageSysId);

        var additionalParams = {
            FlattenType: 'fully_flatten' // donot_flatten // partially_flatten // fully_flatten
        };

        var v = new sn_pdfgeneratorutils.PDFGenerationAPI();

        var result = v.fillFieldsAndMergeSignature(params.fieldMap, params.fillablePdfSysId, params.targetTableName, params.targetRecordSysId, pdfSignRequestor, params.targetPdfName, additionalParams);
        return result;
    },
    type: 'HRTaskSignature'
};

Total Views: 1285

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *