Hi,
We try to call the function in the node.js/java script file as suggested in the link below, but face an error message as below when we call the function from Sage X3.
Error
Do you have any suggestions on how to problem solve.
Thanks
Hi,
We try to call the function in the node.js/java script file as suggested in the link below, but face an error message as below when we call the function from Sage X3.
Error
Do you have any suggestions on how to problem solve.
Thanks
Hello,
I might need more details to help you find the problem. Can you show me your gumu.js and X3 code please?
Thanks
Thank you so much for your reply
gumu.js code is as below
Sage X3 Code to call gumu.js file
Hi Alvan-M hope you might be able to review the code please. Appreciate your time and efforts
Stacey Orrock the input into variable MODULE 'bundles\aptus\lib\gumu._js' contain invalid JSON string characters, namely '\'. Change the input to 'bundles/aptus/lib/gumu._js'. You can validate that your input does not contain any invalid JSON characters by using the escjson function, i.e. MODULE = escjson(MODULE).
Thank you for your response we tried that and got
Stacey Orrock the error indicates that the Java script you are attempting to execute or one of its dependencies cannot be found. Not sure which version of Sage X3 you are working with, or which JavaScript you are attempting to execute.
Hi we where just testing with the blog from Greytrix and could not get that to work. we are using V12 pu33.
Thanks
Stacey Orrock with since V12 your declaration inside your gumu.js should be:
var httpClient = require(“@sage/syracuse-lib/src/http-client/httpClient”);
instead of:
var httpClient = require(“sage/syracuse-lib/src/http-client/httpClient”);
Hello,
Here's how i got it to work:
{ "name": "greytrix", "description": "greytrix", "version": "1.0.0", "author": "gumu", "private": true, "sage": { "x3": { "extensions": { "4gl-apis": [ { "module": "./lib/gumu._js" }, { "module": "./lib/gumu.js" }, { "module": "./lib/gumu" } ] } } } }
"use strict"; //directory depends on your setup var httpClient = require("@sage/syracuse-lib/src/http/client/httpClient"); var http = require("http"); const https = require("https"); //const request = require("request"); exports.TOBASE64 = function(_,InData) { var base64data = Buffer.from(InData).toString('base64'); return base64data; };
Local Clbfile RESHEAD(0) Local Clbfile RESBODY(0) Local Integer STATUSCODE Local Char FUNCTION(255) : FUNCTION = "TOBASE64" Local Char MODULE(100) : MODULE = "bundles/lib/gumu" Local Char MODE(10) : MODE = "wait" Local Clbfile ARGUMENTS : ARGUMENTS = '"","Your message"' STATUSCODE = func ASYRWEBSER.EXEC_JS(MODULE,FUNCTION,MODE,ARGUMENTS,"",0,"","0",RESHEAD,RESBODY) Infbox num$(RESBODY)
Here's how I got xa1-crypto to work.
Subprog TESTENCRYPTDECRYPT() Local Clbfile ENC_HEAD Local Clbfile DEC_HEAD Local Clbfile ENC_BODY Local Clbfile DEC_BODY Local Clbfile SHA1 Local Clbfile RESHEAD Local Clbfile RESBODY #################################################################################################################################################################################### #DIGEST #################################################################################################################################################################################### Local Clbfile PLAINTEXT : PLAINTEXT = "Message" Local Clbfile ENCRYPTION_KEY : ENCRYPTION_KEY = "cbi327ecbizc2781Y" STATUSCODE = func ASYRWEBSER.EXEC_JS("xa1-crypto/lib/crypto-helper", "digest", "sync", '"' + escJson(PLAINTEXT) + '"', "0", 0, "", "0", RESHEAD, RESBODY) If STATUSCODE = 200 Infbox "Digested" - '"'+escJson(PLAINTEXT)+'"' Infbox RESBODY Else Infbox "Failed Digestion" Infbox num$(RESHEAD) Endif #################################################################################################################################################################################### #ENCRYPT #################################################################################################################################################################################### STATUSCODE = func ASYRWEBSER.EXEC_JS("xa1-crypto/lib/crypto-helper", "encrypt", "sync", '"' + escJson(PLAINTEXT) + '", "' + escJson(ENCRYPTION_KEY) + '"', "", 0, "", "0", ENC_HEAD, ENC_BODY) If STATUSCODE = 200 Infbox "Encrypted" - '"'+escJson(PLAINTEXT)+'"' Infbox ENC_BODY Else Infbox "Failed encryption" Infbox num$(ENC_HEAD) Endif #################################################################################################################################################################################### #DECRYPT #################################################################################################################################################################################### STATUSCODE = func ASYRWEBSER.EXEC_JS("xa1-crypto/lib/crypto-helper", "decrypt", "sync", '"' + escJson(ENC_BODY) + '", "' + escJson(ENCRYPTION_KEY) + '"', "", 0, "", "0", DEC_HEAD, DEC_BODY) If STATUSCODE = 200 Infbox "Decrypted" - '"'+escJson(ENC_BODY)+'"' Infbox DEC_BODY Else Infbox "Failed decryption" Infbox num$(DEC_HEAD) Endif #################################################################################################################################################################################### End
{ "name": "xa1-crypto", "description": "Crypto helper for Sage X3 4GL", "version": "1.0.0", "author": "ACME Corp.", "private": true, "sage": { "x3": { "extensions": { "4gl-apis": [{ "module": "./lib/crypto-helper" }] } } } }
"use strict"; var crypto = require('crypto'); exports.digest = function(text) { var hash = crypto.createHash('sha1'); hash.update(text, 'utf8'); var result = hash.digest('hex'); return result; }; exports.encrypt = function(text, key) { var cipher = crypto.createCipher('aes-256-cbc', key); var encrypted = cipher.update(text, 'utf8', 'base64'); encrypted += cipher.final('base64'); return encrypted; }; exports.decrypt = function(text, key) { var decipher = crypto.createDecipher('aes-256-cbc', key); var decrypted = decipher.update(text, 'base64', 'utf8'); decrypted += decipher.final('utf8'); return decrypted; };
Hi Stacey Orrock ,
if you are trying to encode and decode in base 64, what don't you use native 4GL instructions ?
online-help.sageerpx3.com/.../
I believe that the question was targeted towards the use of javascript libraries rather than the use of encode, decode in base 64. The base 64 encryption was just the example that was used.
Hello Alban-M ,
I've follow your tuto line after line but I still have the same issue :
Do you have any idea of what can be the problem ?
Thank
Jules
*Community Hub is the new name for Sage City