Create a button, which gives the details from another table

  • 0
  • 1
  • Question
  • Updated 7 years ago
  • Answered
I am trying to create a button in "orders" table called details, on clicking this details it should give the hyperlink to related products from the "products" table in the same cell of the grid report where the button appears.
I have started to write the code but i am facing some issues, here the code

(function () {

var QBU_field;
var apptoken = "blajkbhdasvasv";

var url = "";
url += "https://www.quickbase.com/db/blank";
url += "?act=API_DoQuery";
url += "&query={3.EX." + QBU_rid + "}";
url += "&clist=22";
url +=apptoken;

$.ajaxSetup({async: false});

alert(url);

$.get(url,function(xml) {
QBU_field=$("product_name",xml).text();
});
alert(QBU_field);
alert("reached here");

//document.location.href="https://www.quickbase.com/db/bhjug8hpi";
})();

This is just the initial step. I am trying to get the product details in the variable QBU_field. But my QBU_field is blank..

And assume i get this working, how to extract each product from that variable and make it into a hyperlink.



Photo of Azh7

Azh7

  • 30 Points

Posted 7 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,184 Points 20k badge 2x thumb
At a minimum you need to have a named parameter for the apptoken along with a value:

url += "&apptoken=" + apptoken;
prompt("url",url);

Using a prompt will allow you to quickly cut and paste the generated URL which you can paste into a second window to check the response.

You don't need to prefix your variables within the closure with the prefix "QBU_" as they are not in the same namespace as QuickBase's global variables (but QBU_rid does need the prefix as it is outside the closure and will collide with QuickBase's global variables).

Go with what works but I would not set async to false even if you have seen it in examples. Instead, place your subsequent code within the callback or use promises.
Photo of Azh7

Azh7

  • 30 Points
Dan Help,

(function () {
  var msg = " Product ID     is '" + QBU_rid ;
  alert(msg);

var display="";
var apptoken = "blahblahblahblah";

//alert("Hi 1");

var url  = "";
url += "https://www.quickbase.com/db/blahblah";
url += "?act=API_DoQuery";
url += "&query={56.EX." + QBU_rid + "}";
url += "&clist=22.3";
url += "&apptoken="+apptoken;


prompt("checking url",url);

$.ajaxSetup({async: false});   

$.get(url,function(xml) {
  $("record", xml).each(function (index, recdata) {
        var product_rec = $("product_name", recdata).text();
        var product_id = $("record_id_",recdata).text();
            display += product_rec + "," + product_id +"\n";
       });
       });

// AFTER I GET THE PRODUCT NAME AND THE RID, I WANT TO DISPLAY IT AS A LINK IN THE SAME CELL FROM WHERE IT WAS TRIGGERED...  TRIED USING YOUR :FOCUS METHOD, BUT WAS NOT SUCCESSFUL. THOUGHT OF USING API_ADDRECORD BUT I DONT WANT TO ADD RECORDS, JUST DISPLAY THEM AS LINKS.

alert("display values "+ display);

/*
var url1 ="";
url1 += "https://www.quickbase.com/db/bhjug8ife";
url1 += "?act=API_AddRecord";
url1 += "&_fid_137=" + display;
url1 += "&apptoken" + apptoken;
*/
alert("reached here");

})();
Photo of Azh7

Azh7

  • 30 Points
Any suggestions here will be much appreciated....
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,184 Points 20k badge 2x thumb
>TRIED USING YOUR :FOCUS METHOD, BUT WAS NOT SUCCESSFUL.

It is pretty simple. Arrange for the button to load a script using $.getScript(...) stored in a user defined page and the code below will replace the contents of the cell which holds the button with the markup you supply (in this case "<h1>Hello World</h1>"):

$.expr[':'].focus = function(a){
return (a ==document.activeElement);
}

$(":focus")
.closest("td")
.html("<h1>Hello World</h1>");

Pastie Database
https://www.quickbase.com/db/bgcwm2m4g?a=dr&rid=194

document.activeElement
https://www.quickbase.com/db/bhnaee82w
Photo of Azh7

Azh7

  • 30 Points
Thanks.. I got that working...
but

.html("<a href=something>" +variable + "</a>");

in that something i need to put the reference of a particular form page, which changes dynamically depending on the records pulled.... I am not able to come to a conclusion for the url which is like "https://www.quickbase.com/db/blahblah?a=er&r=e3&rl=dss"
... how can i five a reference of such a form...
Photo of Azh7

Azh7

  • 30 Points
Any Help....

This conversation is no longer open for comments or replies.