Page 1 of 2

nuRunQuery is not defined

Posted: Sun Apr 09, 2023 7:11 pm
by luca.ongaro
Hi, I am new to nuBuilder.
I am trying to run a query in the Custom Code section of a form, but what I get is nothing at all.
This is the error message I find in the browser console:

418:8 Uncaught ReferenceError: nuRunQuery is not defined
at <anonymous>:8:15
at b (jquery-3.6.4.min.js?ts=1:2:866)
at He (jquery-3.6.4.min.js?ts=1:2:48496)
at S.fn.init.append (jquery-3.6.4.min.js?ts=1:2:49847)
at nuAddJavaScript (nuform.js?ts=20230409190610:5338:12)
at nuBuildForm (nuform.js?ts=20230409190610:169:3)
at successCallback (nuajax.js?ts=20230409190610:131:4)
at Object.success (nuajax.js?ts=20230409190610:15:41)
at c (jquery-3.6.4.min.js?ts=1:2:28447)
at Object.fireWith [as resolveWith] (jquery-3.6.4.min.js?ts=1:2:29192)
(

Can you help? Thanks

Re: nuRunQuery is not defined

Posted: Sun Apr 09, 2023 8:42 pm
by kev1n
Hi,

nuRunQuery() is a PHP function, it can only be run in a BE, BS etc. event, not in the form's Custom Code.
If you want to run a query from JavaScript, you will have to call a Procedure with nuRunPHPHidden()

Re: nuRunQuery is not defined

Posted: Mon Apr 10, 2023 9:38 am
by luca.ongaro
Thank you so much for your prompt reply. Got it. It was a stupid question...
What I need to do is to have a given field in a form to default to a query result when I open that form to add a new record.
Any tip?
Thanks in advance

Re: nuRunQuery is not defined

Posted: Mon Apr 10, 2023 9:39 am
by kev1n
What type of field/object is it?

Re: nuRunQuery is not defined

Posted: Mon Apr 10, 2023 9:57 am
by luca.ongaro
Currently I am trying using a simple input/text object

Re: nuRunQuery is not defined

Posted: Mon Apr 10, 2023 10:27 am
by kev1n
Either use nuOnProcessObjects() or nuAddJavaScript() in the BE (Before Edit) PHP event.

Re: nuRunQuery is not defined

Posted: Tue Apr 11, 2023 12:39 pm
by luca.ongaro
Me again...
I am trying to use the nuOnProcessObjects() method, but where and how should I define $f to get $f->objects?
Thanks

Re: nuRunQuery is not defined

Posted: Tue Apr 11, 2023 1:07 pm
by kev1n
There's no need to define $f. It's predefined.

Re: nuRunQuery is not defined

Posted: Tue Apr 11, 2023 1:53 pm
by luca.ongaro
OK. I am not a PHP geek, but the following BE code:

function nuOnProcessObjects() {

for ($i = 0; $i < count($f->objects); $i++) {

if ($f->objects[$i]->id == 'doc' {
$f->objects[$i]->value = 'myDummyText';
break;
}

}

}

cause the following error message (from browser console) in core/nuapi.php:1

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

Where am I wrong?

Re: nuRunQuery is not defined

Posted: Tue Apr 11, 2023 2:03 pm
by kev1n
Paste the code here: https://phpcodechecker.com/