Hey all. I’ve got an Automation script seemingly close to get the Youtube Video ID from a full URL which I found here.
Script from link above
<script type="text/javascript">
function youtube_parser(url){
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
var match = url.match(regExp);
return (match&&match[7].length==11)? match[7] : false;
}
</script>
Goal:
I’m trying to take a Youtube URL in an existing field: myInput
or https://www.youtube.com/watch?v=YAIlMUX9VLg
and strip out only YAIlMUX9VLg to pass onto the next step (or output to the field Video ID, doesn’t matter).
I’m feel like I’m so close but at the end of my copy/paste/adapt coding skills. Here’s my code:
let myTable = base.getTable("Video Tracker");
let query = await myTable.selectRecordsAsync();
let myUpdateField = myTable.getField('Video ID');
console.log(query.records);
function youtube_parser(myInput){
var regExp = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
var match = myInput.match(regExp);
if (match && match[2].length == 11) {
return match[2];
} else {
//error
}
}
var ytOUT = youtube_parser;
output.set('myOutput', ytOUT);
And the error I get that I cannot make heads or tails of:
ERROR
TypeError: Invalid arguments passed to output.set(key, value): • value should be a JSON-serializable type, not a function (undefined)
at main on line 16
Here’s my Edit Script screen overall

and the Automation overall if it helps:

Thanks for any help.

