Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Use of nuSetProperty / NuGetProperty Topic is solved

Questions related to using nuBuilder Forte.
Post Reply
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Use of nuSetProperty / NuGetProperty

Unread post 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
Last edited by yvesf on Thu Jan 23, 2025 9:24 pm, edited 3 times in total.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Use of nuSetProperty / NuGetProperty

Unread post 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.
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Use of nuSetProperty / NuGetProperty

Unread post 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
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Use of nuSetProperty / NuGetProperty

Unread post 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
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Use of nuSetProperty / NuGetProperty

Unread post 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);
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Use of nuSetProperty / NuGetProperty

Unread post 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
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Use of nuSetProperty / NuGetProperty

Unread post 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');
You do not have the required permissions to view the files attached to this post.
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Use of nuSetProperty / NuGetProperty

Unread post 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
Post Reply