{"id":23361,"date":"2021-09-21T05:20:55","date_gmt":"2021-09-21T05:20:55","guid":{"rendered":"http:\/\/www.greytrix.com\/blogs\/sagex3\/?p=23361"},"modified":"2021-09-21T05:20:59","modified_gmt":"2021-09-21T05:20:59","slug":"how-to-write-encode-function-on-node-js-by-passing-input-argument-from-x3","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/sagex3\/2021\/09\/21\/how-to-write-encode-function-on-node-js-by-passing-input-argument-from-x3\/","title":{"rendered":"How to write encode function on node.js by passing input argument from X3"},"content":{"rendered":"\n<p>Node.js files contain tasks that will be executed on certain events. Node.js uses an event-driven, non-blocking I\/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Node.js applications are written in JavaScript, and can be run within the Node.js runtime.Node.js files have extension &#8220;._js&#8221;<\/p>\n\n\n\n<p><strong>STEP1: Creating Node.js File and save it as gumu.js<\/strong><\/p>\n\n\n\n<p>Writing Node.js code with build in modules and user defined modules and save it on Root Drive:\\Sage\\SyracuseComponent\\syracuse\\bin\\node_modules\\bundles\\ greytrix\\lib\\gumu.js<\/p>\n\n\n\n<p>Create the folder under bundles(greytrix\\lib)<\/p>\n\n\n\n\n\n<p><strong>Fig 1.1-Code Description:<\/strong><\/p>\n\n\n\n<p><strong>The &#8220;use strict&#8221; Directive:<\/strong><\/p>\n\n\n\n<p>&#8220;use strict&#8221;:&nbsp;Defines that JavaScript code should be executed in &#8220;strict mode&#8221;. It helps to write cleaner code, like preventing from using undeclared variables.<\/p>\n\n\n\n<p><strong>Built-in Modules:<\/strong><\/p>\n\n\n\n<p>To make Node.js act as an HTTP server include the module. Include the module using&nbsp;require()&nbsp;function with the name of the module.<\/p>\n\n\n\n<p><strong><em>Server:var&nbsp;http = require(&#8216;http&#8217;);<\/em><\/strong><strong><em><\/em><\/strong><\/p>\n\n\n\n<p>Application has access to the HTTP module, and is able to create a server.<\/p>\n\n\n\n<p>Node.js has a built-in module called HTTP, which allows Node.js to transfer data over the Hyper Text Transfer Protocol (HTTP).<\/p>\n\n\n\n<p>To identity the httpclient we can declare<\/p>\n\n\n\n<p><strong><em>Client : var httpClient = require(&#8216;syracuse-httpclient\/lib\/httpClient&#8217;);<\/em><\/strong><strong><em><\/em><\/strong><\/p>\n\n\n\n<p><strong>Create user defined Modules:<\/strong><\/p>\n\n\n\n<p>Use the&nbsp;exports&nbsp;keyword to make properties and methods available outside the module file.<\/p>\n\n\n\n<p><em>Example: exports.TOBASE64=function(_,InData){&#8230;..};<\/em><\/p>\n\n\n\n<p><strong>STEP2:<\/strong> <strong>Passing argument from x3 client<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"571\" height=\"320\" src=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2021\/09\/Fig-2.1-X3-script-file.png\" alt=\"\" class=\"wp-image-23364\" srcset=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2021\/09\/Fig-2.1-X3-script-file.png 571w, https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2021\/09\/Fig-2.1-X3-script-file-300x168.png 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><figcaption><strong>Fig 2.1: X3 script file<\/strong><\/figcaption><\/figure>\n\n\n\n<p><strong>Fig 2.1-Code Description:<\/strong><\/p>\n\n\n\n<p>The function EXEC_JS is located in the ASYRWEBSER library and <strong><em>func&nbsp;ASYRWEBSER.EXEC_JS<\/em><\/strong> is used to execute node.js file and its definition is the following<\/p>\n\n\n\n<p>MODULE:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The name of the published node.js JavaScript module.<\/li><\/ul>\n\n\n\n<p>FUNCTION&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The name of the JavaScript function to be called.<\/li><\/ul>\n\n\n\n<p>MODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>A mode to determine if the call is synchronous or asynchronous (&#8216;sync&#8217; or &#8216;wait&#8217;).<\/li><\/ul>\n\n\n\n<p>ARGUMENTS<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Multiple arguments delimited by &#8216;,&#8217; ; It can be JSON format or every types.<\/li><\/ul>\n\n\n\n<p>ENCODINGS<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Specify if arguments must be base64 encoded or not. A list of &#8216;0&#8217; or &#8216;1&#8217; separated by &#8216;,&#8217;.<\/li><li>Can be empty if no base64 encoding is needed for any argument.<\/li><li>Important: when it is not an empty string, it must match exactly the number of arguments.<\/li><li>Base 64_IN.<\/li><\/ul>\n\n\n\n<p>CALLB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Specify the location of callback function. This is needed only for &#8216;wait&#8217; mode.<\/li><li>The value depends on the function.<\/li><li>-1 is the value to say that the callback location is the last parameter.<\/li><\/ul>\n\n\n\n<p>RETURNS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Used to filter JSON Objects .<\/li><\/ul>\n\n\n\n<p>RETURNS_ENC&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Specify the needs to encode the response to base64 or not. Can be &#8216;0&#8217; or &#8216;1&#8217;<\/li><li>Base 64_OUT<\/li><\/ul>\n\n\n\n<p>RESHEAD&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The http response header.<\/li><\/ul>\n\n\n\n<p>RESBODY&nbsp;&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The Response body. The response will be stored in this variable.<\/li><\/ul>\n\n\n\n<p>STATUSCODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The status code returned by the JavaScript runner module.<\/li><\/ul>\n\n\n\n<p><strong>STEP 3: Output<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"201\" height=\"135\" src=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2021\/09\/Fig-3.1-Encoded-output.png\" alt=\"\" class=\"wp-image-23365\"\/><figcaption><strong>Fig 3.1:  Encoded output<\/strong><\/figcaption><\/figure>\n\n\n\n<p><strong><u>Note:<\/u><\/strong> Restart the Sage Syracuse &#8211; NODE0 service when changes done on gumu.js file<\/p>\n\n\n\n<p>This blog helps us to understand how to write encode function on node.js server by passing input parameter from X3 client.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>About Us<\/strong><\/h2>\n\n\n\n<p>Greytrix \u2013 a globally recognized and one of the oldest Sage Development Partners is a one-stop solution provider for Sage ERP and Sage CRM organizational needs. Being acknowledged and rewarded for multi-man years of experience and expertise, we bring complete end-to-end assistance for your technical consultations, product customizations, data migration, system integrations, third-party add-on development, and implementation competence.<\/p>\n\n\n\n<p id=\"block-28013e99-0882-44c6-b705-7b16c85053b2\">Greytrix&nbsp;has some unique integration solutions developed for&nbsp;<a href=\"https:\/\/www.greytrix.com\/sage-crm\/\">Sage CRM<\/a>&nbsp;with Sage ERPs&nbsp;namely&nbsp;<a href=\"https:\/\/www.greytrix.com\/sage-x3-erp\/\">Sage X3<\/a>,&nbsp;<a href=\"https:\/\/www.greytrix.com\/sage-intacct\/\">Sage Intacct<\/a>,&nbsp;<a href=\"https:\/\/www.greytrix.com\/sage-100-erp\/\">Sage 100<\/a>,&nbsp;<a href=\"https:\/\/www.greytrix.com\/sage-500-erp\/\">Sage 500<\/a>,&nbsp;and&nbsp;<a href=\"https:\/\/www.greytrix.com\/sage-300-erp\/\">Sage 300<\/a>. We also offer best-in-class&nbsp;Sage ERP&nbsp;and&nbsp;Sage CRM&nbsp;customization and development services&nbsp;to&nbsp;Business&nbsp;Partners,&nbsp;End&nbsp;Users, and Sage PSG worldwide. Greytrix&nbsp;helps in&nbsp;the migration of Sage CRM from&nbsp;Salesforce | ACT! | SalesLogix | Goldmine | Sugar CRM | Maximizer. Our Sage CRM Product Suite includes&nbsp;addons like&nbsp;&nbsp;Greytrix Business Manager,&nbsp;Sage CRM Project Manager,&nbsp;Sage CRM Resource Planner,&nbsp;Sage CRM Contract Manager,&nbsp;Sage CRM Event Manager,&nbsp;Sage CRM Budget Planner,&nbsp;Gmail Integration,&nbsp;Sage CRM Mobile Service Signature,&nbsp;Sage CRM CTI Framework.<\/p>\n\n\n\n<p id=\"block-4bc42a09-fb13-4598-8137-ce5f7b91ce28\">Greytrix is a recognized&nbsp;Sage Champion Partner&nbsp;for GUMU&#x2122; Sage X3 \u2013 Sage CRM integration listed on&nbsp;<a href=\"https:\/\/www.sage.com\/marketplace\/asb_ListingDetail?listingId=a1h24000007PC3aAAG\" target=\"_blank\" rel=\"noreferrer noopener\">Sage Marketplace<\/a>&nbsp;and Sage CRM \u2013 Sage Intacct integration listed on&nbsp;<a href=\"https:\/\/marketplace.intacct.com\/MPListing?lid=a2D0H000007kiHyUAI\" target=\"_blank\" rel=\"noreferrer noopener\">Sage Intacct Marketplace<\/a>. The&nbsp;<a href=\"https:\/\/www.greytrix.com\/gumu\/\" target=\"_blank\" rel=\"noreferrer noopener\">GUMU&#x2122; Cloud framework<\/a>&nbsp;by Greytrix forms the backbone of cloud integrations that are managed in real-time for the processing and execution of application programs at the click of a button.<\/p>\n\n\n\n<p id=\"block-76376301-1c3e-4250-8a09-727595a606f0\">For more information on our integration solutions, please contact us at&nbsp;<a href=\"mailto:sage@greytrix.com\">sage@greytrix.com<\/a>. We will be glad to assist you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Node.js files contain tasks that will be executed on certain events. Node.js uses an event-driven, non-blocking I\/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Node.js applications are written in JavaScript, and can be run within the Node.js runtime.Node.js files have extension &#8220;._js&#8221; STEP1: Creating Node.js\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/2021\/09\/21\/how-to-write-encode-function-on-node-js-by-passing-input-argument-from-x3\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5,8,10,2796],"tags":[3401,3407,3406,3402,3404,3408,3400,3403],"class_list":["post-23361","post","type-post","status-publish","format-standard","hentry","category-faq","category-features","category-sage-erp-x3","category-standard","category-technical","tag-aruguments","tag-asyrwebser","tag-asyrwebser-exec_js","tag-bundles","tag-encoding","tag-httpclient","tag-node-js","tag-x3-and-node-js"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/23361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/comments?post=23361"}],"version-history":[{"count":2,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/23361\/revisions"}],"predecessor-version":[{"id":23367,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/23361\/revisions\/23367"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/media?parent=23361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/categories?post=23361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/tags?post=23361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}