Welcome to the nuBuilder Forums!

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

nuRunQuery is not defined

Questions related to customising nuBuilder Forte with JavaScript or PHP.
luca.ongaro
Posts: 64
Joined: Sun Jan 22, 2023 7:03 pm

nuRunQuery is not defined

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

Re: nuRunQuery is not defined

Unread post 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()
luca.ongaro
Posts: 64
Joined: Sun Jan 22, 2023 7:03 pm

Re: nuRunQuery is not defined

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

Re: nuRunQuery is not defined

Unread post by kev1n »

What type of field/object is it?
luca.ongaro
Posts: 64
Joined: Sun Jan 22, 2023 7:03 pm

Re: nuRunQuery is not defined

Unread post by luca.ongaro »

Currently I am trying using a simple input/text object
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: nuRunQuery is not defined

Unread post by kev1n »

Either use nuOnProcessObjects() or nuAddJavaScript() in the BE (Before Edit) PHP event.
luca.ongaro
Posts: 64
Joined: Sun Jan 22, 2023 7:03 pm

Re: nuRunQuery is not defined

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

Re: nuRunQuery is not defined

Unread post by kev1n »

There's no need to define $f. It's predefined.
luca.ongaro
Posts: 64
Joined: Sun Jan 22, 2023 7:03 pm

Re: nuRunQuery is not defined

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

Re: nuRunQuery is not defined

Unread post by kev1n »

Paste the code here: https://phpcodechecker.com/
Post Reply