Page 1 of 1

Return value of CSPro user defined functions in Javascript

Posted: December 14th, 2021, 10:40 pm
by htuser
Dear CSPro Developer Team,
Testing the new CSPro 7.7 API, rather than using a standalone javascript hashing library, i'm using the CSPro logic hash function in a very simple user defined function
function string hashString(string value)

string hashResult=hash(value, 5);

errmsg ("le hash est %s",hashResult);
exit hashResult;
end;
However, assign his result to a javascript variable failed:
var nomCategorie = document.getElementById("categoryName").value;
var idCategorie=CSPro.runLogicAsync('hashString("nomCategorie");');
var arguments = {nomCategorie,idCategorie};
alert(JSON.stringify(arguments));
Please what i'm doing wrong?
Thanks in advance for your support.

Re: Return value of CSPro user defined functions in Javascript

Posted: December 15th, 2021, 8:35 am
by Gregory Martin
The asynchronous version isn't going to return the result of the CSPro function. So your options are to call it synchronously:
var idCategorie = CSPro.runLogic('hashString("nomCategorie");');
If you do this, you will want to get rid of the errmsg in your function because synchronous calls shouldn't display UI.

Alternatively, call it asynchronously and use the CSPro.getAsyncResult function in the post-run callback (the second argument to CSPro.runLogicAsync). For example:
CSPro.runLogicAsync('hashString("nomCategorie");', 'let idCategorie = CSPro.getAsyncResult(); /* ... do something ... */');

Re: Return value of CSPro user defined functions in Javascript

Posted: December 15th, 2021, 11:01 am
by htuser
Thanks a lot for explanations.