Page 1 of 1

Unable to understand Procedures in nuBuilder

Posted: Sun Oct 23, 2022 11:25 am
by mjd300
Not sure if this is the right section, or if it should be General (feel free to move).

I cannot figure out how Procedures work in nuBuilder.

I have tried the following:
  • a Run object that calls a procedure
  • a button (Input) that has an onclick using nuRunPHPHidden('ProcedureName', 1)
I initially tried a curl call and an echo, which came back as an uncaught error (though in the error was the correct returned data). For clarify, the Curl call works when run directly.

So now I am experimenting by just echoing a string.

It always comes back with an uncaught error (as shown in image).

I understand that maybe you cannot echo / print results, but I do not see any procedure to deal display of returned data. It seems unlikely we could use javascript there to update an element directly.

I also tried nuSetFormValue on a Word field that is in the same form, but nothing happened (no error). It seems that is not for this use-case

What am I (and the documentation) missing here?

Thanks.

Re: Unable to understand Procedures in nuBuilder

Posted: Sun Oct 23, 2022 11:43 am
by kev1n
If you use echo() or var_dump() in the Procedure, use nuRunPHP.

Or use nuJavascriptCallback when you run a Procedure with nuRunPHPHidden() to pass data from PHP to JS.

nuSetFormValue() can only be used in a Lookup's After Browse event.

Re: Unable to understand Procedures in nuBuilder

Posted: Sun Oct 23, 2022 12:01 pm
by mjd300
Ok, thanks. I'll try that with newRunPHP.

I did manage to update a Word field, with this, so that is a good starting point as well.

$js = " document.getElementById('word_result').innerHTML = 'It worked!'; ";
nuJavascriptCallback($js);

Re: Unable to understand Procedures in nuBuilder

Posted: Sun Oct 23, 2022 12:27 pm
by mjd300
To check (and for anyone else who wants to do this), this worked to pass a PHP variable to JS, but not sure it is the best way (or nuBuilder way):

$js = " document.getElementById('word_result').innerHTML = " . "\"" . $var . "\"" . "; ";

It seemed to only work when I had the quotes around the variable, when the $js is used in nuJavascriptCallback($js).

Re: Unable to understand Procedures in nuBuilder

Posted: Sun Oct 23, 2022 12:41 pm
by kev1n
This should do the job too:

Code: Select all

$js = " nuSetText('word_result','$var'); ";

Re: Unable to understand Procedures in nuBuilder

Posted: Mon Oct 24, 2022 9:51 pm
by mjd300
Thanks. Yes, that's much neater