I am wondering if a value pulled into the Data Feature (field) of List Detail block be made available to the javascript that I put into the custom code block on the same page?
If so, can someone suggest a code snipped that would demonstrate how that value can be referenced in by section?
Sure. Suppose you have a page with a List Details block on it, and suppose that the record that the List Details block is displaying has a field called Name whose value is David.
You can write the following in JavaScript to fetch that value out:
Hi @dcoletta, thanks for getting in touch. It was indeed the issue. Once I included the setInterval function it worked - neat trick. I’m still learning the ins and outs of the platform. I originally had the call inside an event listener on the window (‘load’ event) - interesting the load event fires before data/elements are available. Guessing it has something to do with the way the platform loads data? Now I use both the window load event and the setInterval method for all calls made. Thanks
@dcoletta thank you for helping out with the script.
I want to share with the community the script that is (was) working for grabbing the recordID from the URL of a Softr page that has a detail block on it. NOTE: the URL must be in the form [core-url]?recordID=[record-id].
<script>
const queryString = window.location.search;
console.log(queryString);
// ?recordId=<some_record_id>
//Parse the query string's parameters
const urlParams = new URLSearchParams(queryString);
//Return the value associated with the search parameter recordId
const recordId = urlParams.get("recordId");
console.log(recordId);
//Prepare to call the recordId
let myIframe = document.getElementById("iframe");
let url_string = "[some-url-string]";
let width = "728";
let height = "90";
let geo = "us";
let customURL =
url_string +
"?cid=" +
recordId +
"&geo=" +
geo +
"&size=" +
width +
"x" +
height;
console.log("Encoded URL: ", encodeURI(customURL));
myIframe.src = customURL;
document.getElementById("myIframe").src = encodeURI(customURL);
</script>
This code was solid… until started tuning for SEO and introduced the SEO:Slug field in my Airtable on top of which the detail block sits. That totally changed the URL of the page…
from: [core-url]?recordID=[record-id]
to: [core-url]/[slug]/r/[record-id]
Needless to say, the code above no longer works.
If someone could suggest how to tweak the code to work with the new URL format, that would be great.