Creating an Outbound Validation Plug-in Implementation for E-Documents
An Outbound Validation Plug-in Implementation for e-documents will enable you to validate the e-document during generation process with your custom logic. You can select an Outbound Validation Plug-in Implementation from the Outbound Validation Plug-in Implementation field in an E-Document Template.
To use custom validation, you must first create a custom plug-in implementation for outbound validation plug-in for e-documents. After this, the plug-in implementation will be available for you to select in the Outbound Validation Plug-in Implementation field on the E-Document Template.
To create this plug-in implementation, you must first create a JavaScript file that must be compatible with SuiteScript 2.0. For more information about creating a Javascript file, see SuiteScript 2.x Script Creation Process.
The following code is a sample plug-in implementation script for outbound validation:
1. /**
2. * @NApiVersion 2.x
3. * @NModuleScope Public
4. * @NScriptType plugintypeimpl
5. */
6. define([], function() {
7.
8. /**
9. *
10. * @param {Object} pluginContext
11. * @param {String} pluginContext.content
12. * @param {String} pluginContext.transactionInfo.transactionId
13. * @param {String} pluginContext.transactionInfo.transactionType
14. * @param {Number} pluginContext.userId
15. * @returns {Object} result
16. * @returns {string} result.success
17. * @returns {String} result.message
18. */
19. function validate(pluginContext) {
20.
21. var result = {
22. success: false,
23. message: "Validation failed."
24. };
25.
26. try {
27.
28. /**
29. * Extract the values from pluginContext
30. */
31.
32. // var content = pluginContext.content;
33. // var userId = pluginContext.userId;
34. // Connect to validation service and get response.
35.
36. /**
37. * Use this information to fetch the transaction data
38. */
39.
40. /*
41. var transactionType = pluginContext.transactionInfo.transactionType;
42. var transactionId = pluginContext.transactionInfo.transactionId;
43. var transObj = record.load({
44. type: transactionType,
45. id: transactionId
46. });
47. */
48.
49. // If successful
50. result.success = true;
51. result.message = "Validation successful!";
52.
53. // Sample result if not successful
54. // result.success = false;
55. // result.message = "Validation failed.";
56.
57. return result;
58.
59. } catch (e) {
60. result.success = false;
61. result.message = e.message;
62. }
63.
64. return result;
65. }
66.
67. return {
68. validate: validate
69. };
70. });
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 |
content |
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. |
|
transactionInfo. |
String |
The type of transaction being validated. |
transactionId and transactionType parameters provide information about the transaction being validated. You can use them together to reference any field value of the transaction using N/search.lookupFields or N/record.load |
transactionInfo. |
String |
The internal ID of the transaction being validated. |
|
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 can implement any custom validation logic on edocString in the validate function. The validate function should return 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 validation is successful. Otherwise, set it to false. |
Required |
message |
String |
Message to be passed to Electronic Invoicing. This message gets displayed in E-Document audit trail of the transaction. |
Required |
The Outbound Validation Plug-in implementation script must have the @NSScriptType plugintypeimpl
.
To create a plug-in implementation record:
-
Go to Customization > Plug-ins > Plug-in Implementations > New.
-
Create a JavaScript file following the sample script.
-
Select the JavaScript file you created, from the Script File field and click Create Plug-in Implementation button.
-
Select the Outbound Validation Plug-in type from the Select Plug-in Type record.
-
Type the information in the required fields on the Plug-in Implementation record.
-
Click Save.
an Outbound Validation plug-in implementation record is created, you can select it in the E-Document Template record. For more information, see Custom Plug-in Creation.
Related Topics
- Creating E-Document Templates
- XPath and Regex Examples for E-Document Templates
- PEPPOL Template
- Understanding Inbound E-Document Templates in JSON Format
- Understanding XSD in Inbound E-Document Templates
- Understanding XSD in Outbound E-Document Templates
- Creating a Digital Signature Plug-in Implementation for E-Documents
- Creating a Custom Plug-in Implementation for E-Document Custom Data Source