Yes i have tried it before and unfortunatly:
Function Error
TypeError: Failed to fetch
If it failed to fetch… probably had the wrong parameters, or parameters were empty when the request was made… remember that it is hard to determine when the script will start running. The columns with the parameters might not be filled yet… it would be best if you made sure to wait for that.
- For testing - all rarametrs are seting inside code column/
- I tried to return url and then use it to fetch by glide fetch column and it works. It mean code column have right url but cant fetch and i dont know why
Hola Alexey!
Let me understand the problem with your code:
let myTrigger = p1;
if (myTrigger == 1) {
const title = “Запись на тренировку Хатха-Йога”;
const phone = “+70000000000”;
const name = “p2”;
const comments = “Тестовый комментарий”;
const url = `https://vektor-systems.bitrix24.ru/rest/13/1f1331sb41fa9r09/crm.lead.add.json?FIELDS[TITLE]=${encodeURIComponent(title)}&FIELDS[PHONE][0][VALUE]=${encodeURIComponent(phone)}&FIELDS[NAME]=${encodeURIComponent(name)}&FIELDS[COMMENTS]=${encodeURIComponent(comments)}`;
const data = await fetch(url);
const json = await data.json();
return json;
}
Can you give 1-2 valid URLs to test them via Glide fetch column and then using this JS?
BTW… Was the myTrigger set to 1? (this kind of things happens)
If myTrigger is a Boolean column, you must check it as true or false
let myTrigger = p1;
if (myTrigger == true) {
/// your code
}
Saludos!
Hi, gvalero! Thanks for income!
Yes trigger is working also for true
Thank you for correcting!
This url gives response
https://vektor-systems.bitrix24.ru/rest/13/4825o4an22hrm2o4/crm.contact.list.json?FILTER[PHONE]=79605463333&SELECT[ID]=
Response
{“result”:[{“ID”:“19525”},{“ID”:“19527”},{“ID”:“19529”},{“ID”:“19531”},{“ID”:“19533”},{“ID”:“19535”}],“total”:6,“time”:{“start”:1681078043.07305,“finish”:1681078043.2366631,“duration”:0.16361308097839355,“processing”:0.10522699356079102,“date_start”:“2023-04-10T01:07:23+03:00”,“date_finish”:“2023-04-10T01:07:23+03:00”,“operating_reset_at”:1681078643,“operating”:0.10519099235534668}}
but not in code column, just in browser or Glide fetch column
Ah, I know what is happening, we need a simple but mandatory detail
Your original JS code returns a JSON structure and this kind of data/structure is not supported by JavaScript column (an array either!). The code must return a string as value therefore, we need to find out and select the JSON objects to assemble our string later.
So a useful code can be something like this:
const url = `https://vektor-systems.bitrix24.ru/rest/13/4825o4an22hrm2o4/crm.contact.list.json?FILTER[PHONE]=79605463333&SELECT[ID]=`;
const data = await fetch(url);
const json = await data.json();
return json.result[0].ID +", " +
json.result[1].ID +", " +
json.result[2].ID +", " +
json.total
Instead, if you want to receive the entire JSON payload from your fetch call as a text, you just need to change:
data.json() → data.text()
and the new code will be:
const url = `https://vektor-systems.bitrix24.ru/rest/13/4825o4an22hrm2o4/crm.contact.list.json?FILTER[PHONE]=79605463333&SELECT[ID]=`;
const data = await fetch(url);
const json = await data.text(); // data.json();
return json
I hope this helps fix your problem as of now.
Feliz noche!
Thank you very much, gvalero!
It so simple, and so useful! And its works!
Thanks!