Return value of CSPro user defined functions in Javascript

Discussions about CSEntry
Post Reply
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Return value of CSPro user defined functions in Javascript

Post 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.
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1792
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Return value of CSPro user defined functions in Javascript

Post 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 ... */');
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Return value of CSPro user defined functions in Javascript

Post by htuser »

Thanks a lot for explanations.
G.VOLNY, a CSProuser from Haiti, since 2004
Post Reply