This topic is locked
[SOLVED]

 ajax.getCurrentRecord() retunring only first row

9/21/2018 9:25:32 AM
ASPRunner.NET General questions
Pete K author

I want to set a session variable when a row is clicked in a list page. So I went to Pages > List Page > Click actions... > Run AJAX snippet and used some code that was proposed by the wizard, modifying it to suit my needs. Here's the relevant code which I placed in the server event:



XVar data = ajax.getCurrentRecord();

result["record"] = data;

XSession.Session["SchCode"] = data["SchCode"];

XSession.Session["SchName"] = data["SchName"];


The problem is that the code always fetches the first record regardless of which row I click. What am I doing wrong?

Pete K author 9/21/2018

I worked it out. It would appear that the code suggested by the wizard is in error -- from what I can conclude from the documentation, getCurrentRecord() does not work on list pages. So I did some more digging and figured out that I can use this code on the client before event to send the field values to the server event as paramaters:



params["SchCode"] = row.getFieldValue("SchCode");

params["SchName"] = row.getFieldValue("SchName");


The server code then becomes:



XSession.Session["SchCode"] = parameters["SchCode"];

XSession.Session["SchName"] = parameters["SchName"];

result["SchName"] = parameters["SchName"];


jadachDevClub member 9/21/2018

Pete, I did somethining similar. This is what I did for server tab and it worked fine.

dynamic record = XVar.Array();

record = button.getCurrentRecord();

result.InitAndSetArrayItem(record["Name"], "Name");

XSession.Session["SessionName"] = record["Name"].ToString();
admin 9/22/2018

ajax.getCurrentRecord(); does work, just double-checked. Make sure that this table as primary key selected, this is important.

Pete K author 9/25/2018

Thanks guys. Sergey was right -- I had neglected to set the PK in ASPR. Odd that it didn't pick it up from the SQL schema as it generally does.