Adding a button to a row that runs PHP. Or, getting the selected row.

Hi there-

How can I add a button to a row in ScriptCase that is hooked to PHP code?

Example: I have a table of users:
user/password/Full_Name/Email

I want a button on each row labelled “Send Welcome Email”.
When you click the button, it runs PHP code. (In this case, I’ll write the PHP code to email that user.)

How can this button be added? I’m a PHP coder, but a bit new to ScriptCase, thanks.

Alternatively, I noticed you can select a row in a grid, but I can’t see where, in the programming, I can get that selected record! If I could get that, I could just use a button on the top of the grid, although I think that’s more confusing for the user.

You can add a new field (i.e.) link to the grid and apply code to that. Also you can create an applicationlink from the grid to the form where you can add a button (add button) and apply code.

What do you mean add a new field?

Here’s what I did that worked:

  • Grid->Fields (folder)->New Field. Called it ClickMe. Type is Text.
  • Grid->Ajax Events->New Ajax Event. Choose the ClickMe field. Action- OnClick. Sample 1 line of code in the event: echo “ha ha!!! :slight_smile: {MyField}”;
  • Grid->Events->OnRecord. Add the text of the field. Code is one line: {ClickMe} = ‘Click me’;

Works well and has a mouseOver.

Still, I wish there was an easier way of doing this, as it’s a pretty fundamental thing to do.

[QUOTE=cyman;13556]What do you mean add a new field?

Here’s what I did that worked:

  • Grid->Fields (folder)->New Field. Called it ClickMe. Type is Text.
    [/QUOTE]

This is exactly what I meant. You can put a image of a button to let it look like one. There’s a sample in the SC library available to show this. Not sure, but I think it’s the helpdesk app.

But How Can I use the parameters in ajax event?

I try use {my_field2} and $my_field2…but I get a error, don’t find the variables(parameters)

I ahve the same Problem, I do not know how to access filed values in my Ajax Events =(
According one example they said {} , but did not work…

Was an expiation of passing parameters in a grid / java event found? Same issue

If you create an ajax event i.e. onchange on a field you can simply use the {} references to the form fields w.o. the need of passing them.

Hi All,

Sorry to ressurect this topic, but having use the above method, i find I can only call {field_1} in the ajax event if the column is visible, but I don’t want that particular column to be visible in the grid.

Any ideas ?

Cheers

I’m looking for the exact same thing…
I have a grid, with a simple button to toggle a customer status (active/inactive)…
An editable grid form is way to complex for such an easy task, but unless the affected field is visible, the ajax event does not work.

Anyone help would be welcome…

Regards
Mariano

use CSS to hide the field AFTER you loaded the page. So just show your field on the FORM, then generate and hide the field. In this case AJAXevent will be made by SC and will be executable.

​​​​​​on elementID/class use

visibility: hidden; or ​​​​​​display: none;

Unfortunately, I want this in a grid, not on a form… .

I’ve found at least a ‘dirty’ workaround…

I first use OnRecord to set my “active/inactive” button to the correct state according to my ‘hidden’ value (the hidden field IS available to OnRecord). Since my button has an image, I set an ‘alt’ tag to whatever I want.


if ({hiddenfield}=='active') {
    {toggleButton} = '<button style=whatever><img src='activebuttonimage.png' alt='buttonIsActive'></button>';
}

Then, Inside the Ajax event, instead of looking for my ‘hidden column’s’ value, I’m using strpos to search for the alt tag’s value, and execute whatever code I need (usually toggling the hidden field), and updating my button’s image.


if (strpos({toggleButton},'buttonIsActive')!=false) { // button is currently active
        $sql="UPDATE table SET hiddenfield='inactive' WHERE whatever"; // change table's field (hidden on grid) to inactive
        {toggleButton} = '<button style=whatever><img src='inactivebuttonimage.png' alt='buttonIsInactive'></button>'; // update the toggle button
    } else { // button is inactive
        $sql="UPDATE table SET hiddenfield='active' WHERE whatever"; // change table's field (hidden on grid) to Active
        {toggleButton} = '<button style=whatever><img src='activebuttonimage.png' alt='buttonIsActive'></button>'; // update the toggle button
    }
sc_exec_sql($sql); // execute the needed sql statement

This would be much easier if the hidden field’s value was available to the Ajax Event.

As a sidenote… this method also works better for me for visible fields… since I do not need to do an sc_ajax_refresh();… it works much faster than reloading the whole grid an checking the current visible fields’ value in side the ajax event.