This topic is locked
[SOLVED]

 Calling a Stored Procedure with parameters from List Page

2/1/2017 2:38:13 AM
PHPRunner General questions
S
Smithy author

Hi everyone,
I am trying to call a stored procedure from a List Page- the procedure simply updates a field in the database based on the id field on the screen.
I have the code attached to a button, which is embedded in each row of a table. I want to grab the iddespool_List value from the row the button is appearing on, and use it in my stored procedure.
But I keep getting an error

Microsoft JScript compilation error: Expected identifier in line 2


Here is my Code:



function OnClient Before(params,ctrl)

{

// Put your code here.

CustomQuery("CALL spUpdateDespoolingComplete('" . $values["iddespool_list"] . "')");

return true;

} // function OnClient Before


Any help is greatly appreciated.
Craig Smith

Admin 2/2/2017

You are trying to run PHP code in Javascript event. This code needs to be placed to Server event.

S
Smithy author 2/3/2017



You are trying to run PHP code in Javascript event. This code needs to be placed to Server event.


Thankyou for your reply Sergey.
Placing the code in the Server Event has indeed removed the error.
However, it is now like the code isn't being executed. I have tried several variations, and placed the code in different Events. What I have found is that, if I place the code in an event, say, in the Process Values event of the View page, it works fine - I assume because the $values array is passed to the event. (The code shown triggers the stored procedure every time I move to a new record, which is not what I want to happen, but is heartwarming to see that the procedure does what I want it to <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81243&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> ).

function ProcessValuesView($values, $pageObject)

{

CustomQuery("CALL spUpdateDespoolComplete('" . $values["iddespool_list"] . "')");

}


However, in the Server event, am I right in thinking that the $values array are not passed to the Event, and therefore the input parameter for my stored procedure doesn't receive a value ?

(Below is the List page, button click event - this doesn't trigger the stored procedure.)



function OnServer($params, $result)

{

CustomQuery("CALL spUpdateDespoolComplete('" . $values["iddespool_list"] . "')");

}


I am simply trying to trigger the MySQL stored procedure when the user clicks my custom button on the List Page, on the current record. I feel I have missed something in the help file, or in how custom button events work.

I have tried passing information from the Client Before event to the Server event (as per the help file) but can't make it work, and I don't understand what 'params' & 'ctrl' do in this case.
I hope this makes my query a little clearer - I thank you in advance for any assistance you can provide.
Kind regards,

Craig Smith

Admin 2/3/2017

The first stop should be PHPRunner manual:

https://xlinesoft.com/phprunner/docs/inserting_button.htm
Examples 1, 2 and 3 explain how to access values of the current record.

S
Smithy author 2/6/2017



The first stop should be PHPRunner manual:

https://xlinesoft.com/phprunner/docs/inserting_button.htm
Examples 1, 2 and 3 explain how to access values of the current record.


Thanks again Sergey.
I have tried and tried so many variants of the examples, but I just can't figure it out.

I have tried these options:



function OnServer($params,$result)

{

while($record=$button->getCurrentRecord())

{

$sql = "CALL spUpdDespoolComplete('" .$record["iddespool_list"]. "')";

CustomQuery($sql);

}
}



and



function OnServer($params,$result)

{

$sql = "CALL spUpdDespoolComplete('" .$values["iddespool_list"]. "')";

CustomQuery($sql);

}


I have tried about eleventy million other variations of the example in the help file, but the references to "$keys", "params", "dal" etc, make no sense to me and I just can't get it to work.
All I am trying to achieve is to get the iddespool_list value passed to my my stored procedure.

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81278&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
This is my editor screen:


[url="<a href="http://imgur.com/EJJMgPb"><img src="https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81278&image=2&table=forumreplies"; title="source: imgur.com" /></a>"]Screen Shot[/url]
I am also not getting the "$result" to appear on the screen after I press the button, which makes me think the parameter (or field value) is not being picked up correctly.

I'm not asking for anyone to write the code for me, I just need some guidance as to what array to use, and if I am even in the right ball park to get this to work.
I would really appreciate a hint of some sort to help me on my way.
Best regards,
Craig Smith

Admin 2/6/2017

A couple of things.

  1. Since you need to call this code from button's Server event you should not be looking at any other code examples as they may not be relevant. The following article in the manual is all you need:

    https://xlinesoft.com/phprunner/docs/inserting_button.htm
  2. If something doesn't work you need to troubleshooting your code. The following article explains how to do that with buttons:

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

S
Smithy author 2/6/2017



A couple of things.

  1. Since you need to call this code from button's Server event you should not be looking at any other code examples as they may not be relevant. The following article in the manual is all you need:

    https://xlinesoft.com/phprunner/docs/inserting_button.htm
  2. If something doesn't work you need to troubleshooting your code. The following article explains how to do that with buttons:

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


Thank you Sergey,
The code that worked for me was from the help file specifically relating to the OnServer event, but I changed "getNextSelectedRecord" to "getCurrentRecord".



function On($params, $result)

{

while($record = $button->getCurrentRecord())

{

$sql = "CALL spUpdateDespoolComplete('";

$sql.= $record["iddespool_list"];

$sql.= "')";

CustomQuery($sql);

}

}


That was just the push I needed. Thanks again.
Craig