Help

Upcoming database upgrades. to improve our reliability at 03:30 UTC on Feb. 25 / 7:30pm PT on Feb. 24. Some users may briefly experience slow load times or error messages. Learn more here

Simple script for beginning developer

Topic Labels: Scripting extentions
874 3
cancel
Showing results for 
Search instead for 
Did you mean: 

Hi everyone! I’m a long-time Airtable user and novice developer. I’m currently teaching myself Javascript and have a small script I’m trying to create (at least I think it’s small/simple).

I want to create a script that loops through a list of sitemap urls and returns the total count of pages for each record to a field in my table called “Page Count”

Screen Shot 2020-03-18 at 11.45.51 AM

So far, I’ve been able to figure out that I can use a bit of javascript to count the number of xml nodes in a document using something like this:

var x = xmlDoc.getElementsByTagName("loc");
return(x.length);

But I’m not sure how to pull in an xml doc hosted at a specific url or loop through airtable records…anyone willing to provide a little direction?

Thanks,
Max

3 Replies 3

you would want to use the fetch() function. something like:

let urlContent = await fetch(sitemapLink)
let text = await urlContent.body()

let to convert that to an xml doc:

let parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");

good luck!

Ahhh thank you so much! This is very helpful for getting started, especially the fetch function and DOMParser

Did you get any errors at first with DOMParser?

I’m getting:
ReferenceError: DOMParser is not defined

From my understanding this isn’t supported?