Setting up Structured Data for Job Postings -> Script Fails

Hey guys,

I’m looking for help with setting up structured data for job pages. There has been a thread on structured data already with @dcoletta @artur and @irestmycase , but in case someone else is building a job board, this might be helpful to keep separate.

I’ve created a formula in Airtable to create a JSON with the structured data (SEO:JSON-LD):
Example of a result:

{
  "@context": "http://schema.org",
  "@type": "JobPosting",
  "title": "Scooter Mechanic",
  "description": "Accelerating EV adoption",
  "datePosted": "2023-04-05T00:00:00.000Z",
  "validThrough": "2023-05-05T00:00:00.000Z",
  "employmentType": "Temporary",
  "hiringOrganization": {
    "@type": "Organization",
    "name": "BOLT",
    "sameAs": "http://www.bolt.earth",
    "logo": ""
  },
  "jobLocation": {
    "@type": "Place",
    "address": {
      "@type": "PostalAddress",
      "streetAddress": "946 21st Cross Road",
      "addressLocality": "Bengaluru",
      "addressRegion": "",
      "postalCode": "560102",
      "addressCountry": ""
    }
  },
  "baseSalary": {
    "@type": "MonetaryAmount",
    "currency": "",
    "value": {
      "@type": "QuantitativeValue",
      "value": "",
      "unitText": "Year"
    }
  }
}

Google is telling me that the data is correct.

I then copied @irestmycase 's script exactly like it is below into the custom header of the Job Details Page:

<script>    
    document.addEventListener("DOMContentLoaded", function() {    
        var waitForData = setInterval(function () {
            if (typeof $ != 'undefined') {
                const recordId = getUrlParam('recordId');
                if (window.records && window.records[recordId] && window.records[recordId].record.fields['SEO:JSON-LD']) {
                    
                    const jsonldScript = document.createElement('script');
                    jsonldScript.setAttribute('type', 'application/ld+json');

                    const structuredData = window.records[recordId].record.fields['SEO:JSON-LD'];
                    
                    jsonldScript.textContent = structuredData;
                    
                    console.log(jsonldScript);
                    
                    document.head.appendChild(jsonldScript);
                    
                    clearInterval(waitForData);
                }
            }
        }, 100);

        function getUrlParam(name) {
            const url = new URL(window.location.href);
            let param;
            for(var key of url.searchParams.keys()) {
                if(key.toLowerCase() === name.toLowerCase()) {
                param = url.searchParams.get(name);
                break;
                }
            }
        
            if(!param && name.toLowerCase() === 'recordid') {
                param = getRecordIdFromPath();
            }
            return param;
        }
        
        function getRecordIdFromPath() {
            let pathName = window.location.pathname;
            if (pathName.indexOf('/r/rec') !== -1) {
                pathName = pathName.substr(pathName.indexOf('/r/rec') + 3);
                if (pathName.indexOf("/") !== -1) {
                pathName = pathName(0, pathName.indexOf('/'))
                }
                return pathName;
            }
            return undefined;
        }
    });
</script>

The console is however giving me this error:

Is there anything I need to adopt in the script to tailor it to my base? Or any other modifications I am not seeing?

Getting this to work would be such a game changer throughout my website, so I’d really appreciate some help :green_heart:
Thanks so much in advance, guys!!!