Page 1 of 1

Use of nuSetProperty / NuGetProperty

Posted: Thu Jan 23, 2025 6:56 pm
by yvesf
Hello,

I am trying to build a solution that uses nuSetProperty / nuGetProperty.
Behind the custom code of a form I have put this code :

Code: Select all

nuSetProperty('hash_cookie','');
nuRunPHPHidden('setHashCookieOnServerSide','');
nuMessage(nuGetProperty('hash_cookie)');
The procedure setHashCookieOnServerSide contains :

Code: Select all

$js="nuSetProperty('hash_cookie','yves');";
nuJavaScriptCallback($js);
When I run this, the result is desperately empty. What is wrong ?
Many thanks,

Yves

Re: Use of nuSetProperty / NuGetProperty

Posted: Thu Jan 23, 2025 7:25 pm
by kev1n
nuRunPHPHidden runs a server-side PHP procedure (setHashCookieOnServerSide) asynchronously. This means the script execution does not pause and wait for nuRunPHPHidden to finish.

The nuGetProperty('hash_cookie') line runs immediately after nuRunPHPHidden is called, but since the callback hasn't been processed yet, the property value hasn't been updated when nuMessage is triggered.

Re: Use of nuSetProperty / NuGetProperty

Posted: Thu Jan 23, 2025 7:57 pm
by yvesf
What is then the best approach to make this working ? Procedure will be always async ? How to know when the procedure has finished ? Another alternative ? thx

Re: Use of nuSetProperty / NuGetProperty

Posted: Thu Jan 23, 2025 9:05 pm
by yvesf
Generally, I found quite difficult to pass data from the client to the serveur vs to the database. Do we have a good example explaining how to best solve that ? I thought that hash cookie was THE solution and it seems it is a little bit more complex.
Many thanks for your help,

Yves

Re: Use of nuSetProperty / NuGetProperty

Posted: Thu Jan 23, 2025 10:29 pm
by kev1n
yvesf wrote: Thu Jan 23, 2025 7:57 pm What is then the best approach to make this working ? Procedure will be always async ? How to know when the procedure has finished ? Another alternative ? thx
In your form's custom code, declare a function called onProcedureComplete(); for example, and add there the code to be executed after the procedure has been executed.

Code: Select all

function onProcedureComplete() {
  nuMessage('Procedure call complete');
}
And in your PHP procedure, call that function:

Code: Select all

$js="nuSetProperty('hash_cookie','yves'); onProcedureComplete();";
nuJavaScriptCallback($js);

Re: Use of nuSetProperty / NuGetProperty

Posted: Fri Jan 24, 2025 12:48 am
by yvesf
Hi Kevin,

It doesn't work with this proposed approach. The only solution I have found is the following :

Code: Select all

$js="nuSetProperty('hash_cookie','yves'); nuMessage(nuGetProperty('hash_cookie'));";
nuJavaScriptCallback($js);
By doing so, you wait the end of the nuSetProperty when you retrieve nuGetProperty.
Many thx,

Yves

Re: Use of nuSetProperty / NuGetProperty

Posted: Fri Jan 24, 2025 4:54 am
by kev1n
yvesf wrote: Fri Jan 24, 2025 12:48 am It doesn't work with this proposed approach.
How did you test it? It seems to be working fine on my end.
Also, I'm curious about the reasoning behind using nuSetProperty().
Wouldn’t it be possible to simply pass a parameter to the onProcedureComplete() function instead?

Procedure "myproc":
myproc.png
Code in form's Custom Code:

Code: Select all

function onProcedureComplete() {
  nuMessage(nuGetProperty('hash_cookie'));
}

nuRunPHPHidden('myproc');

Re: Use of nuSetProperty / NuGetProperty

Posted: Fri Jan 24, 2025 9:07 am
by yvesf

Code: Select all

nuMessage(nuGetProperty('hash_cookie)');
cannot be put directly after the call to the procedure on the custom code's form. It has to be put directly in php code or via a procedure.
Many thx for your help and implication,

Yves