Signing Date on HTML Document Templates

leahdany
Giga Guru

Hello,

 

Is there a way within an HTML Document Template to add/map a signing date? I know this can be done on a PDF Document Template, but since what I'm generating is an offer letter there are dynamic field values and the ability to edit the document after previewing it before the document task is initiated.

 

I need a way to record the signing date from the subject person before the final PDF gets generated. Any ideas?

1 ACCEPTED SOLUTION

Here's the BR conditions and script that I use.

 

jeffiral_0-1724021217169.png

 

 

(function executeRule(current, previous /*null when async*/) {

    var htmlBody = current.body.toString();

    var curDate = new GlideDate();
    var formattedDate = curDate.getByFormat('dd-MMM-yyyy');
    var actionType = current.participant.toString();

    if (actionType == '1450bf7c937f42d0b6c1b92b1bba10ef' && current.state.changesTo(3)) {
        // Manager Acknowledgement and state changes to Closed
        htmlBody = htmlBody.replace('<span style="color: #ffffff;">DateManagerAcknowledgement</span>', '<span style="color: #000000;">' + formattedDate + '</span>');

    } else if (actionType == '1200bbfc937f42d0b6c1b92b1bba10bc') {
        // Employee Acknowledgement
        if (current.state == 1) { // Ready
            var prevTask = current.previous_task.sys_id;
            var prevtskQuery = new GlideRecord('sn_doc_task');
            if (prevtskQuery.get(prevTask)) {
                var prevtskDate = prevtskQuery.getValue('closed_at');
                var prvformattedDate = new GlideDate(prevtskDate).getByFormat('dd-MMM-yyyy');
                htmlBody = htmlBody.replace('<span style="color: #ffffff;">DateManagerAcknowledgement</span>', '<span style="color: #000000;">' + prvformattedDate + '</span>');
            }
        }

        if (current.state.changesTo(3)) { // Closed
            htmlBody = htmlBody.replace('<span style="color: #ffffff;">DateEmployeeAcknowledgement</span>', '<span style="color: #000000;">' + formattedDate + '</span>');
        }
    }

    current.setValue('body', htmlBody);
    current.update();

})(current, previous);

 

 

View solution in original post

8 REPLIES 8

abirakundu23
Mega Sage

Hi @leahdany ,

After "Initiating the document task" only we can sign the PDF template which is expected OOB behavior. I don't think signing will be possible before creation of Initial Document Task.

In order to achieve you have to Customize OOB flow as per your business requirement.

Please mark helpful & correct answer if it's really worthy for you.

jiral
Giga Sage

On the sn_doc_task, there's the "body" field that captures the html value of the document to be signed. You can create a placeholder e.g. DocumentSignDate.

 

Then create a Business Rule with whatever conditions you may have based on the participants, document task template etc. and do a .replace for the DocumentSignDate with the formatted date out of the document task closed/update date. That's what I have implemented and that's based on how the signature gets added to html document after signing (dig in to the flow and that's how it does it for the signature). 

@jiral Are you able to provide the business rule you use?

Here's the BR conditions and script that I use.

 

jeffiral_0-1724021217169.png

 

 

(function executeRule(current, previous /*null when async*/) {

    var htmlBody = current.body.toString();

    var curDate = new GlideDate();
    var formattedDate = curDate.getByFormat('dd-MMM-yyyy');
    var actionType = current.participant.toString();

    if (actionType == '1450bf7c937f42d0b6c1b92b1bba10ef' && current.state.changesTo(3)) {
        // Manager Acknowledgement and state changes to Closed
        htmlBody = htmlBody.replace('<span style="color: #ffffff;">DateManagerAcknowledgement</span>', '<span style="color: #000000;">' + formattedDate + '</span>');

    } else if (actionType == '1200bbfc937f42d0b6c1b92b1bba10bc') {
        // Employee Acknowledgement
        if (current.state == 1) { // Ready
            var prevTask = current.previous_task.sys_id;
            var prevtskQuery = new GlideRecord('sn_doc_task');
            if (prevtskQuery.get(prevTask)) {
                var prevtskDate = prevtskQuery.getValue('closed_at');
                var prvformattedDate = new GlideDate(prevtskDate).getByFormat('dd-MMM-yyyy');
                htmlBody = htmlBody.replace('<span style="color: #ffffff;">DateManagerAcknowledgement</span>', '<span style="color: #000000;">' + prvformattedDate + '</span>');
            }
        }

        if (current.state.changesTo(3)) { // Closed
            htmlBody = htmlBody.replace('<span style="color: #ffffff;">DateEmployeeAcknowledgement</span>', '<span style="color: #000000;">' + formattedDate + '</span>');
        }
    }

    current.setValue('body', htmlBody);
    current.update();

})(current, previous);