This topic is locked
[SOLVED]

 getting JSON error when using Field Events

5/8/2020 11:27:28 AM
PHPRunner General questions
L
lcslouis author

I am getting the following error on a field Events handler:



pageevents_viewbodyupgradecal.js?41_1588949293:140 Uncaught TypeError: Converting circular structure to JSON

--> starting at object with constructor 'constructor'

| property 'layoutHelper' -> object with constructor 'Runner.PDLayout'

--- property 'page' closes the circle

at JSON.stringify (<anonymous>)

at submit (pageevents_viewbodyupgradecal.js?41_1588949293:140)

at constructor.Runner.pages.fieldsEvents.BodyLevel_event1 (pageevents_viewbodyupgradecal.js?41_1588949293:173)

at constructor.<anonymous> (RunnerAll.js?35002:6763)

at constructor.callHandler (RunnerAll.js?35002:4854)

at constructor.fireEvent (RunnerAll.js?35002:5006)

at constructor.on.buffer (RunnerAll.js?35002:8909)

at callHandler (RunnerAll.js?35002:4854)

at call (RunnerAll.js?35002:398)

submit @ pageevents_viewbodyupgradecal.js?41_1588949293:140

Runner.pages.fieldsEvents.BodyLevel_event1 @ pageevents_viewbodyupgradecal.js?41_1588949293:173

(anonymous) @ RunnerAll.js?35002:6763

callHandler @ RunnerAll.js?35002:4854

fireEvent @ RunnerAll.js?35002:5006

on.buffer @ RunnerAll.js?35002:8909

callHandler @ RunnerAll.js?35002:4854

call @ RunnerAll.js?35002:398

setInterval (async)

delay @ RunnerAll.js?35002:423

(anonymous) @ RunnerAll.js?35002:4759

dispatch @ loadfirst.js?35002:3

r.handle @ loadfirst.js?35002:3


My Code

Client Before:



var ctrlProfile = ctrl.getPeer('Profile');

params["value"]=ctrlProfile;


Server:


$result["QiRate"] = DBLookup("select QiRateCombined FROM ViewProfileRealm where ID='".$params['value']."'");

$currentRealm = DBLookup("select CurrentBodyRealm From CharacterProfile where ID='".$params['value']."'");

$result["ReqQi"] = DBLookup("select CBRequired FROM BodyRealm where ID ='".$currentRealm."'");


Client After:


//Fields being used on page

var ctrlCurrentQi = this.getValue('CurrentQi');

var ctrlNeedQi = ctrl.getPeer(pageObj,'QiNeeded');

var ctrlNeedTime = ctrl.getPeer(pageObj,'TimeNeeded');
// Set Value Of NeedQi Field

ctrlNeedQi.setValue(Number(result["ReqQi"] - ctrlCurrentQi.getValue()));

// Math Functions

var NeedQi = Number(result["ReqQi"] - ctrlCurrentQi.getValue());

ctrlNeedTime.setValue(Number(Math.celi(NeedQi / result['QiRate'])*5/86400));


How Can I fix this?
I am on windows 10 using version 10.4(Build 35002 x64)

Sergey Kornilov admin 5/8/2020

From the look of it - the error is happening in the Server part of the event and you need to see the exact error message. Here is the article that explains what to https://xlinesoft.com/phprunner/docs/troubleshooting_custom_buttons.htm

W
wpl 5/8/2020

Louis,
shouldn't your "Client Before" rather look like:



var ctrlProfile = ctrl.getPeer('Profile');

params["value"]=ctrlProfile.getValue();


Regards

L
lcslouis author 5/9/2020

I wound up moving all the code to the before record added or updated events.
One issue I am continuing to have is that the field events are not trigging properly or sometimes not at all.
I have my field event using text change or change the field is using the Lookup Wizard Type

I have also tried using just one event and it still doesn't trigger.
This is what it does
Client Before


var ctrlProfile = ctrl.getPeer('Profile');

// Sample:

params["value"] = ctrlProfile.getValue();

if (ctrlProfile.getValue() < 1)

return false;


Server


$result["CurrentQi"] = DBLookup("select CurrentQi from CharacterProfile where ID=".$params['value']);


Client After


var ctrlCurrentQi = ctrl.getPeer('CurrentQi');
if (ctrlCurrentQi < result['CurrentQi'])

ctrlCurrentQi.setValue( result['CurrentQi']);


There is no error in the browser.

W
wpl 5/10/2020



Client After


var ctrlCurrentQi = ctrl.getPeer('CurrentQi');
if (ctrlCurrentQi < result['CurrentQi'])

ctrlCurrentQi.setValue( result['CurrentQi']);


There is no error in the browser.


Maybe you can give this a try in Client after:



var ctrlCurrentQi = ctrl.getPeer('CurrentQi');
if (ctrlCurrentQi.getValue() < result['CurrentQi'])

ctrlCurrentQi.setValue( result['CurrentQi']);


Regards

Sergey Kornilov admin 5/10/2020

There is a huge difference between event not being triggered and not doing what you want it to do and you need to find out which one.
Again, use the article I suggested to see if the call to buttonhandler.php is happening at all and what exactly it returns:

https://xlinesoft.com/phprunner/docs/troubleshooting_custom_buttons.htm

L
lcslouis author 5/10/2020

Ok After changing the code to this:
Client before



var ctrlProfile = ctrl.getPeer('Profile');

params["value"] = ctrlProfile.getValue();

if (ctrlProfile.getValue() < 1)

return false;


Server



$result['CurrentQi'] = DBLookup("select IFNULL(CurrentQi,0) as CurrentQi from CharacterProfile where ID=".$params['value']);


Client After



var ctrlCurrentQi = ctrl.getPeer('CurrentQi');

var PageCurrentQi = ctrlCurrentQi.getValue();

var ProfileCurrentQi = result['CurrentQi'];
if (PageCurrentQi <- ProfileCurrentQi)

ctrlCurrentQi.setValue(ProfileCurrentQi);


This is the error I Get:



Uncaught TypeError: Cannot read property 'CurrentQi' of undefined
Sergey Kornilov admin 5/10/2020

You need to find out which specific line of the code produces this error:

https://xlinesoft.com/phprunner/docs/troubleshooting_javascript_errors.htm

L
lcslouis author 5/10/2020

It's saying that the server tab $result['CurrentQi'] is not defined or it can't read it.
this is the line that is producing the error



var ProfileCurrentQi = result['CurrentQi'];


This is the server that sets the result



$result['CurrentQi'] = DBLookup("select IFNULL(CurrentQi,0) as CurrentQi from CharacterProfile where ID=".$params['value']);
Sergey Kornilov admin 5/11/2020

Keep digging. The next step is to print the SQL query from the Server event and make sure that it is correct and returns results.

L
lcslouis author 5/11/2020

Ok I have figured out the issue.
The issue is being caused by the debugger.

I turned off the debugger and now it works properly.
I have also noticed that some of my Lookup Wizard Fields when debugger is on also do not work properly and produce an error. If I turn off the debugger they work properly.

Sergey Kornilov admin 5/11/2020

This makes total sense. Outputting SQL queries or other debug info will break all AJAX functionality like buttons, field events, popup windows, lookup wizards in AJAX mode etc.