How would I go about placing buttons within the grid rows? I need custom links for each record and one button in the toolbar isn’t what I need for this.
Good morning NoAlias. The basic process I use all the time is this:
You have a normal grid application. let’s say you want a button or clickable icon to appear in a certain column if the conditions for a specific row or record are met.
You use the onRecord event to make the visual change for each record. So below is some code I used to show a button with a special icon , depending on conditions. I am using the value of a different column to test for a ‘Yes’ or ‘No’ to make a button, with an icon. Just throwing the icon thing in there, as I like to have visual queues for users.
The {visit} column could be a column generated automatically as part of my SQL select settings , or in this case I added a field manually. Either way, at the onRecord event you can override or replace or modify any content/value.
Now the button itself has no html hyperlink (you could), as I am using in this case the SC linking system for that column. You go to your LINKS settings on the left hand grid menu, and make a Link for that column. Note that any record that has any value in that {visit} column, be it a number from the database or in my case here, the code for the button, will have the Linking action.
Notice I also have a 3rd condition where I just blank out the field, which makes it have no button, and therefore no link.
Using this with grids, I have created some really great informational screens for users. You can use this to build screens that help users change settings or visit other parts of your application, depending on what the data is.
Note that in the SC link, you can make a global variable in the target app, so that when you make the link, you can pass one or more values to the target. There is only 1 link possible for each ‘button’, but in this way the target can know how to use the passed value in the link to take appropriate action.
Hope that helps,
Jamie
if ({secondfield} == ‘Yes’)
{
$VisitIcon = "<IMG SRC='../_lib/img/grp__NM__ico__NM__home_selected_32 - Copy.png' STYLE='height:16px; width: 16px;'>";
{visit} = "<button class='scButton_default'>".$VisitIcon." Visit</button>";
}
elseif ({secondfield} == ‘No’)
{
$VisitIcon = "<IMG SRC='../_lib/img/grp__NM__ico__NM__home_notselected_32 - Copy.png' STYLE='height:16px; width: 16px;'>";
{visit} = "<button class='scButton_default'>".$VisitIcon." Visit</button>";
}
else
{
// show nothing in the column for that record
{visit} = “”;
}
Thank you so much for the detailed post onmountain. It really got me thinking and testing. My problem here is, although my variable that defines the new column works as you have suggested, I have problems with my field variables. Your example lists a variable named {secondfield}. When I try using field variables in the onRecord event, my application outputs “Undefined variable: secondfield” and I have confirmed my field exists. Is there something else I need to do?
I didn’t use {table.column}, only {column} as my variable reference
Sounds like perhaps you are using a join or otherwise referencing fields from multiple tables in your SQL. So it is using that composite name. In your SQL you can also create a simplified name for a specific column. I am 99% SC will use that simplified name. It uses the AS statement. https://www.w3schools.com/sql/sql_alias.asp
Sound like you figured it out Congrats!
Jamie