Creating a Digital Signature Plug-in Implementation for E-Documents

A Digital Signature plug-in implementation for e-documents will enable you to generate digitally signed e-documents. You can select a digital signature plug-in from the Digital signature Plug-in Implementation field in an e-document template record to digitally sign e-documents. Only the XML or JSON files are generated with a digital signature. The generated PDF files are not digitally signed.

You must first create a custom plug-in implementation for digital signature and then implement it in NetSuite. After this, the plug-in will be available for you to select from the Digital Signature Plug-in Implementation field on the e-document template record. To create this plugin implementation, you must first create a JavaScript file for the digital signature plug-in implementation. The JavaScript file must be compatible with SuiteScript 2.0. For more information about creating a Javascript file, refer to the help topic SuiteScript 2.x Script Creation Process.

The plug-in script must return an object with the following function:

          /**
 * Copyright (c) 2019, Oracle NetSuite  its affiliates. All rights reserved.
 *
 * @NApiVersion 2.x
 * @NModuleScope Public
 * @NScriptType plugintypeimpl
 */

define(["N/crypto/certificate", "N/file"], function(certificate, file) {
    /**
     * @param {Object} pluginContext
     * @param {String} pluginContext.unsignedString
     * @param {String} pluginContext.subsidiaryId
     * @param {String} pluginContext.tranType
     * @param {String} pluginContext.tranId
     * @param {Number} pluginContext.userId
     *
     * @returns {Object} result
     * @returns {string} result.success
     * @returns {String} result.signedString
     * @returns {String} result.message
     */

    function signDocument(pluginContext) {
        var unsignedString = pluginContext.unsignedString;

        /* Extract the other required values from pluginContext:
                            var subsidiaryId = pluginContext.subsidiaryId;
                            var tranType = pluginContext.tranType;
                            var tranId = pluginContext.tranId;
                            var userId = pluginContext.userId;
        */

        /* Sample params for N/certificate.signXml()
                        var rootTag = "RootTag";
                        var certificateId = "custcertificatesfd";
                        var algorithm = "SHA1";
        */

        var result = {
            success: true,
            signedString: unsignedString,
            message: "This is a sample implementation of Digital Signature.",
        };

        /**
         * Call services to sign the string
         */
        try {
            /*
                                var signedXML = certificate.signXml({
                                    algorithm : algorithm,
                                    certId : certificateId,
                                    rootTag : rootTag,
                                    xmlString : unsignedString
                                });
      
                                result.success  = true;
                                result.signedString = signedXML.asString();
                                result.message = "Document signed successfully";
                            */
        } catch (e) {
            result.success = false;
            result.signedString = "";
            result.message = e.message;
        }

        return result;
    }

    return {
        signDocument: signDocument,
    };
}); 

        

This script takes the input pluginContext which is a JSON object. The parameters of this object are listed in the following table.

Parameter

Type

Description

Remarks

unSignedString

String

This field holds the generated e-document of a transaction in XML or JSON format. The format depends on its selection in the E-Document Template used for generation. The e-document is not digitally signed.

 

subsidiaryId

String

This field holds the Subsidiary ID of a transaction.

This parameter can be blank if the subsidiary information is unavailable in the transaction.

tranType

String

This field displays the type of transaction.

tranId along with tranType provides context about the transaction being digitally signed. You can use them together to reference any field value of the transaction using N/search.lookupFields or N/record.load

tranID

String

This field displays the internal ID of the transaction.

userId

number

This field holds the internal ID of the current logged in user.

This field value can be used wherever there is a requirement to refer to the current logged in user. For example, to update e-document audit trail by shared module API, userId can be used in owner property.

This script must implement digital signature process on an unsigned XML or JSON string. For example Suitescript 2.0 module N/crypto/certificate. This results in a signed XML or JSON string which must be returned in a JSON object with parameters listed in the following table.

Parameter

Type

Description

Required/Optional

success

 

Valid Values are either true or false. Set the value to true, if the digital signature plug-in implementation is successful and e-document is digitally signed. A string will be generated. Otherwise, set it to false.

Required

signedString

String

This parameter holds the signed string when the digital signature plug—in implementation is successfully completed.

Required

message

String

Message to be passed to Electronic Invoicing. This message gets displayed in E-Document audit trail of the transaction.

Required

Important:

The digital signature plug-in implementation script must have the @NSScriptType plugintypeimpl.

To create a plug-in implementation record:

  1. Go to Customization > Plug-ins > Plug-in Implementations > New.

  2. Create a JavaScript file following the sample script.

  3. Select the JavaScript file you created, from the Script File field and click Create Plug-in Implementation button.

  4. Select the Digital Signature for E-Document plug–in type from the Select Plug-in Type record.

  5. Type the information in the required fields on the Plug-in Implementation record.

  6. Click Save.

a digital signature plug-in implementation record is created, you can select it from the E-Document Template record. For more information, see Custom Plug-in Creation and Digital Signing.

Related Topics

General Notices