Forum Discussion
JohnBarulich1
8 years agoQrew Cadet
Thanks Dan,
In your code snippet previously stated, it doesn't look like we are specifying any context for the selection. How would we specify context for this selection? How would this statement, which specifies position, be executed within the script if it will not fire until the button is pushed?
I can't seem to get a simple button onto the top with
$("table[qbdbid=" + dbidTable + "] tr:first").before("<tr><td><a href=# id=QBU_Button class='Vibrant Success'>Process Selected Records</a></td></tr>");
In your code snippet previously stated, it doesn't look like we are specifying any context for the selection. How would we specify context for this selection? How would this statement, which specifies position, be executed within the script if it will not fire until the button is pushed?
I can't seem to get a simple button onto the top with
[iol] & "myScript.js" & [/iol]
&
"<a class='QBU_Button Vibrant Success'>Button</a>"
- _anomDiebolt_8 years agoQrew EliteDisplay a table report and paste this code into the console:
var dbidTable = "your table dbid";
It will splice a button atop the report and establish a listener for clicks on that button. When you click the button the callback will execute in this case alerting a message.
$("table[qbdbid=" + dbidTable + "] tr:first").before("<tr><td><a href=# id=QBU_Button class='Vibrant Success'>Pinch Me</a></td></tr>");
$("#QBU_Button").on("click", function(event) {
alert("Ouch!");
});
To implement this you could set up the IOL technique and include the IOL field [-] in the report - typically as the last column of the report to not call attention to itself (it will be a skinny column). The formula for [-] will be just this:[iol] & "myScript.js" & [/iol]
The code snippet you pasted is for setting up a button on each row of a report:[iol] & "myScript.js" & [/iol]
Although it would normally pass the [Record ID#] through a data attribute:
&
"<a class='QBU_Button Vibrant Success'>Button</a>"[iol] & "myScript.js" & [/iol]
And obtain the record id in the script as follows:
&
"<a class='QBU_Button Vibrant Success' " &
" data-rid='" & [Record ID#] & "'" &
">Button</a>"$("a.QBU_Button").on("click", function(event) {
});
var rid = this.dataset.rid;
var message = 'You clicked on record with rid=${rid}';
alert(message);
BTW, I think it is best to always name your code page with the prefix "module" followed by the name of the table and perhaps the function of the script. Examples:moduleTable1.js
moduleTable1Form1.js
moduleTable1UpdateSomething.js - JohnBarulich18 years agoQrew CadetHey Dan,
I ran my code within the console and it does everything I needed. Displays a button above the table, fires off my script, and completes my task.
However, this script does not execute when put into a code page with the IOL set up correctly.
From my understanding, the script does not run until an individual record is open, so how can my script be executed, which puts the button above my dbid table, when we are not viewing a record?
Everything is working perfectly until this last step - _anomDiebolt_8 years agoQrew Elite>From my understanding, the script does not run until an individual record is open, so how can my script be executed, which puts the button above my dbid table, when we are not viewing a record?
This is not correct. Post your code to work towards a solution. - JohnBarulich18 years agoQrew Cadetfunction main(){
var dbidTable = "blahblah";
$("table[qbdbid=" + dbidTable + "] tr:first").before("<tr><td><a href=# id=QBU_Button class='Vibrant Success'>Calculate Time Between Stops</a></td></tr>");
$("#QBU_Button").on("click", function(event) {
getDiff();
alert("Button was clicked");
});
}
main();
This is a snippet from my script. When running it in the console from the table dbid page, the button is correctly created above the table and executes my getDiff function. I must not understand the real details behind the IOL if my original understanding is not correct, because from my own testing, the code is NEVER ran unless we are viewing, editing, or adding a record.
How can my code, which puts a button above the table, be executed if we are never accessing an individual record?
My IOL is set up for this table, iol variables are there, the form is setup. Everything is in place. What could be the problem? - _anomDiebolt_8 years agoQrew EliteYou are probably not including the iol field on the report. It is normally named [-] and placed as the last column in the report to not call attention to itself. You can debug this and other scenarios by placing console.log() statements in your script,
- JohnBarulich18 years agoQrew CadetAre you referring to the Fields under Settings of the table? I have the iol set up there:
[iol] & "myScript.js" & [/iol]
All appropriate values unchecked. I have the IOL set up for many tables and haven't had this issue until this project, I'm not sure what I could be doing wrong. - _anomDiebolt_8 years agoQrew EliteYes that is the iol field typically named [-]. Is [-] included in the report? If so it will display as a skinny column with the heading "-" and nothing displayed in any of the rows.
- JohnBarulich18 years agoQrew CadetNo, it was not included in the report. That was definitely the problem. My teammate and I got it working. Thanks Dan!