This topic is locked
[SOLVED]

 row.getFieldValue fails with error

1/28/2020 9:35:47 AM
PHPRunner General questions
J
jaffleck author

I am getting a javascript error in the Client Before event of a custom grid button on a list page. Here is the code:
var artist_id = row.getFieldValue("artistid");
Here is the error I get:
RunnerAll.js?33576:2931 Uncaught TypeError: Cannot read property 'trim' of undefined

at Runner.AjaxRow.getFieldValue (RunnerAll.js?33576:2931)

at Object.pageObj.buttonEventBefore.Random (button_Random.js?33576:2)

at constructor.clickHandler (RunnerAll.js?33576:369)

at HTMLAnchorElement.callHandler (RunnerAll.js?33576:283)

at HTMLAnchorElement.dispatch (loadfirst.js?33576:1)

at HTMLAnchorElement.r.handle (loadfirst.js?33576:1)

I think this is telling me that my artist_id variable is undefined, but I have no idea why. Am I not understanding how to use the row parameter in this event?
I tried row.getKeys() but then I get an error that row.getKeys is not a function.
If I run this code:
str = JSON.stringify(row, null, 4);

alert(str);


I get:
{

[indent]"row":{

[indent]"id":5,

"rowInd":1

"contextRowId":5,

"isEditOwnRow":true,

"gridLayout":0,

"keyFields":[

[indent]"artistid"[/indent]

],

"keys":[

[indent]"2"[/indent]

],

"masterKeys":{

[indent]"albums":{

[indent]"masterkey1":"2"[/indent]

},

"attributions":{

[indent]"masterkey1":"2"[/indent]

},

"artist_recordings":{

[indent]"masterkey1":"2"[/indent]

}

[/indent][/indent]},

[/indent]

This tells me that row is properly assigned. How do I retrieve the artistid value?
I'm running PHPRunner 10.2 build 33576x64.
What am I missing?

A
acpan 1/28/2020

Show more lines of your codes will help
var artist_id = row.getFieldValue("artistid"); does not seems to be the cause.
ACP

J
jaffleck author 1/30/2020



Show more lines of your codes will help
var artist_id = row.getFieldValue("artistid"); does not seems to be the cause.
ACP

nng
I have removed all code in the custom button events other than the row.getFieldValue function call in the client before event (nothing in the server event and nothing in the client after event) and I still get the error message. If I comment out that one line of code in the client before event, I do not get any errors, so it has to be the row.getFieldValue call that is triggering the error. Correct?

A
acpan 1/30/2020

var artist_id = row.getFieldValue("artistid");
works perfectly fine on my PHPR build 34262 (Latest) verified both on the grid of a standalone table and child table of a master table.
Check:

  1. you have no other code that triggers the error eg. in your Javascript Onload Event of the list page.
  2. Make sure the field name artistid is not "uncheck" in your Fields Section in your PHPRunner, so that the artistid can be seen by the javascript of the grid/list.
    Note: To hide a field but still make it available for Javascript, go to Fields Section of PHPR, "check" on the field and go to Columns by device and uncheck Desktop and Smartphone to hide it.
  3. Make sure artistid is the fieldname and NOT artist_id
  4. or use button methods in Server Event:
    Note: Field artistid must be visible or hidden but available for the grid/list before you do this. (i.e. point 2 above)

$record = $button->getCurrentRecord();

$result["artistid"]=$record["artistid"];


Client After Event:



var artistid = result["artistid"];

alert(artistid);



5. Reset the page if necessary => go to Editor of your PHPRunner, reset the page.
If you still have problem, suggest you try the same on another clean table (try until you can do so on a simple case).

C
ckranichDevClub member 1/31/2020

my Noob halfcent:
row.getFieldValue("fieldname")
=> recently noticed that this only is successful if the field is actually visible/used in the grid

if this field is in table but not in grid, it will fail. in this case I used DB-API to retrieve field with a select based on field that is in grid.

A
acpan 1/31/2020

@ckranich, I think you can also do so in point 2 above, in this case, you can avoid calling DB-API for every row.



my Noob halfcent:
row.getFieldValue("fieldname")
=> recently noticed that this only is successful if the field is actually visible/used in the grid

if this field is in table but not in grid, it will fail. in this case I used DB-API to retrieve field with a select based on field that is in grid.

C
ckranichDevClub member 2/1/2020



@ckranich, I think you can also do so in point 2 above, in this case, you can avoid calling DB-API for every row.


Many Thanks for advice, noted...

(In this case I don't call each row but only execute once a custom button (Select Production Order for Production Line) is clicked)

J
jaffleck author 2/6/2020



Many Thanks for advice, noted...

(In this case I don't call each row but only execute once a custom button (Select Production Order for Production Line) is clicked)


It turns out this was an issue with the build. I upgraded to the latest build and the issue disappeared!