Forum Discussion
- ChayceDuncan2Qrew CadetYou can write JS into a formula-url using the following syntax:
javascript: {
//enter your code here
}
If you're trying to do a doQueryCount - you'll have to do a couple things
1) Easiest method is to do a GET against your table using doQuery Count
2) Parse the XML response to get the count
3) Do another GET - this time an EditRecord call to store that value somewhere. So logging it as a record somewhere - or editing a field with the current count - your choice
So like:
javascript: {
$.get(' url for doQueryCount ',function(data) {
//parse the response
$.get(' editRecord ')
})
}
Chayce Duncan | Technical Lead
(720) 739-1406 | chayceduncan@quandarycg.com
Quandary Knowledge Base - MuraliGangineniQrew CadetHello Chayce,
Thanks for your reply.
Can you please provide any sample code for that . - ChayceDuncan2Qrew CadetThis should get you started hopefully - you'll need to swap out your own DBID and realm / apptoken info as appropriate
var text urlD = "https://yourrealm.quickbase.com/db/dbid?a=API_DoQueryCount";
var text urlE = "https://yourrealm.quickbase.com/db/dbid?a=API_EditRecord&rid=***&_fid_**=";
"javascript: {" &
"$.get(' " & $urlD & "',function(data,success) {" &
"console.log(data);" &
"var count = data.getElementsByTagName('numMatches')[0].innerHTML;" &
"console.log(count);" &
"$.get('" & $urlE & "' + count);" &
"});" &
"}"
The gist -
Do your doQueryCount - store that value in a variable count
Make another editRecord call - and pass in the variable count as part of the call
Chayce Duncan | Technical Lead
(720) 739-1406 | chayceduncan@quandarycg.com
Quandary Knowledge Base - MuraliGangineniQrew CadetYes, I changed the urlD and urlE as per my tables and i inserted the above code into my Formula URL Field. In the Field properties, i have selected "Display as button on forms and reports". Now on the form its is showing as a button but when i click on the button its not working. I mean its not clickable and it is not updating the count value to a field.
My doubt here is that the output of Formula URL button should be a URL link. But here we are inserting Javascript code in the Formula URL which gives the output to be a JS Code instead of URL. I suspect it is the reason that the button is not working. - ChayceDuncan2Qrew CadetIf you've copied it exactly as I've coded it above - it is likely working to some extent - but you may have a minor error somewhere. I can confirm that I tested the above in a test app of mine - and the output of a url button does not necessarily have to be a link. Have you opened up the network tab or the console in your browser to see if you are receiving any syntax or network issues?
Additionally - I didn't add anything to the above sample that would actually do anything visual on the screen. It only did the API Calls and then stopped. If you are looking for some kind of 'action' to occur - I would suggest a window.location.reload() so the page just refreshes.
So in the above -
"javascript: {" &
"$.get(' " & $urlD & "',function(data,success) {" &
"console.log(data);" &
"var count = data.getElementsByTagName('numMatches')[0].innerHTML;" &
"console.log(count);" &
"$.get('" & $urlE & "' + count,function(data,success) {" &
"window.location.reload();" &
}); &
"});" &
"}"
Something like that should work
Chayce Duncan | Technical Lead
(720) 739-1406 | chayceduncan@quandarycg.com
Quandary Knowledge Base - MuraliGangineniQrew CadetYes,
Its working but the URL of API_DoQueryCount contains single quotes within the URL . It causes the error. So, i replaced with double quotes and by using ESCAPE CHARACTER(\). After that it worked fine.
Thank you.. - ChayceDuncan2Qrew CadetGreat. Glad it worked out
Chayce Duncan | Technical Lead
(720) 739-1406 | chayceduncan@quandarycg.com
Quandary Knowledge Base