Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'id') #67

Open
blvckeasy opened this issue Mar 25, 2024 · 0 comments
Open

TypeError: Cannot read properties of undefined (reading 'id') #67

blvckeasy opened this issue Mar 25, 2024 · 0 comments

Comments

@blvckeasy
Copy link

// экземпляр Client
const client = require('./client.js');

const run = async () => {
/*
базовые методы работы с объектом Lead описаны в интерфейсе ILead
на сайте библиотеки https://usefulweb.github.io/AmoCRM/interfaces/api_activeRecords_Lead.ILead.html
*/
const lead = await client.leads.getById(123);
lead.name = 'Ivan';
lead.price = 100;

await lead.save();

// вы можете менять и читать любые свойства сделки, которые передаются при её создании и обновлении
console.log(lead.id); // 123

/* Создание новой сделки */
const newLead1 = new client.Lead;

// является ли сделка новой (на основе наличия id у объекта)
lead.isNew(); // true

newLead1.name = 'Walter Scott';
await newLead1.save();
lead.isNew(); // false

// вы можете передать параметры сделки объектом
const newLead2 = new client.Lead({
    name: 'Walter Scott'
});
newLead2.price = 100;
await newLead2.save();

// ... спустя какое-то время сделка может обновиться на сервере
// fetch обновит параметры текущей сделки
const fetchedLead = await newLead2.fetch();

};

run();

/home/blvckeasy/node-apps/amocrm/node_modules/amocrm-js/dist/api/activeRecords/mixins/hasCreate.js:12
this.id = first.id;
^

TypeError: Cannot read properties of undefined (reading 'id')
at HasEmbeddedTags. (/home/blvckeasy/node-apps/amocrm/node_modules/amocrm-js/dist/api/activeRecords/mixins/hasCreate.js:12:33)
at Generator.next ()
at fulfilled (/home/blvckeasy/node-apps/amocrm/node_modules/tslib/tslib.js:166:62)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.13.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant