Search Results for 'form.getRecords'
-
Search Results
-
Inspired by this post detailing how to get watched TV shows, I decided to attempt a Movie import script via TheMovieDB’s API. I’m very new to scripting (really only used iOS Shortcuts) and have gotten stuck and could use some direction or assistance.
The big issue I can’t seem to crack is iterating through the JSON for to pull out the cast and add them to the cast table on the form. I’ve looked through the example of the above of pulling the singular episode details, but the JSON for TheMovieDB is more robust than OMDB and I’ve confused myself.
Any Ideas?
var tmdbAPI = 'xxx'; var title_id = 'fld-7f17a3883cf742ca90a732565f687953'; var released_id = 'fld-4f1d3a5878914910954b65c2f782abfd'; var imdbid_id = 'fld-0b8bd8338d8f494aa5b7099c42230e70'; var poster_id = 'fld-bace3b81b9ab4cc9951a9445d12a63b3'; var summary_id = 'fld-d16b4361266b48ee9c3b88afd29fd5ac'; var runtime_id = 'fld-f096b51db4c447e18bf10298135dfaa8'; var tagline_id = 'fld-ac1ad056b5004ed8a19f8d272ae01e2b'; var cast_id = 'fld-0b85d9aef49f4fd58726f6830a03ba11'; var actor_id = 'fld-07249465a7ea45e8830da27e62b3121d'; var role_id = 'fld-bf225b3c443248fd97c5737312acd28b'; var itemID; function fetchDetailsFromURL() { fetchURL = <code>https://api.themoviedb.org/3/movie/${itemID}?api_key=${tmdbAPI}&language=en-US</code>; return Utils.getJsonFromUrl(fetchURL); } function fetchCastFromURL() { fetchURL = <code>https://api.themoviedb.org/3/movie/${itemID}/credits?api_key=${tmdbAPI}&language=en-US</code>; return Utils.getJsonFromUrl(fetchURL); } function getCast() { var cast = fetchCastFromURL() return cast } function getData() { var film = fetchDetailsFromURL(); var imdbID = film.imdb_id; console.log(imdbID) var itemIds = new Set(); var currentItemsByImdbID = {}; var allCurrentItems = form.getRecords(); for (let currentItems of allCurrentItems) { currentItemsByImdbID[currentItems.getFieldValue(imdbid_id)] = currentItems; itemIds.add(currentItems.getFieldValue(imdbid_id)); } let newRecord; if (itemIds.has("http://imdb.com/title/" + imdbID)) { Utils.alertWithMessage(film.title + ' already exists.', 'Sorry.'); } else { newRecord = form.addNewRecord(); newRecord.setFieldValues({ [title_id]: film.title, [released_id]: film.release_date, [imdbid_id]: "http://imdb.com/title/" + film.imdb_id, [summary_id]: film.overview, [runtime_id]: film.runtime, [tagline_id]: film.tagline, }) } var Poster = "https://www.themoviedb.org/t/p/w1280/" + film.poster_path if (Poster != null) { newRecord.addPhotoFromUrlToField(Poster, poster_id); } form.saveAllChanges(); } var prompter = Prompter.new(); prompter.cancelButtonTitle = 'Cancel'; prompter.continueButtonTitle = 'Go'; prompter.addParameter('TMDB Number', 'itemID'); prompter.show('Enter an TMDB code', getData)
Here are the TMdb API details: https://developers.themoviedb.org/3/movies/get-movie-credits
Hi !
I’ve a movie database in which there’s a Tag pick list, made of checkboxes. I want to find how many different records have a certain item in this pick list checked.
So thinking the pick list returned something I wasn’t sure of, I tried to get the type of the object, but all I am getting is undefined.
var value = movie_form_records[index].getFieldValue(movie_form_tags_id);
console.log(typeof value);
(console output is “undefined”)So when I try this :
var pos = value.search(“Feel good”);It never returns any item, despite the fact that some of the records have this tag. I know this because using the search filter, I can find several movies for which this tag is checked.
My loop goes through all the records and make the following test :
if (pos >-1) {
nombre++;
}But when I am running the code, I am getting the following output in the console :
2021-03-10, 8:17:57 AM / Movies / Feel good
Feel good: TypeError: undefined is not an object (evaluating ‘value.search’), line:(null)
Feel good: TypeError: undefined is not an object (evaluating ‘value.search’), line:(null)The whole code is :
function Feel_Good() {
var nombre = 0;
var movie_form = document.getFormNamed(‘Movies’);var movie_form_tags_field = movie_form.getFieldNamed(‘Tags’);
var movie_form_tags_id = movie_form_tags_field.getId();var movie_form_records = movie_form.getRecords();
for (var index = 0, count = movie_form_records.length; index < count; index++) {
var value = movie_form_records[index].getFieldValue(movie_form_tags_id);
var pos = value.search(“Feel good”);
if (pos >-1) {
nombre++;
}}
return nombre;
}So.. what am I doing wrong ? I’m a total newbie at JavaScript. So maybe I missed something somewhere.
Thanks,
Ray