Merge pull request #1520 from automatisch/AUT-533
feat(vtiger-crm): add new contacts trigger
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import newCases from './new-cases/index.js';
|
||||
import newContacts from './new-contacts/index.js';
|
||||
|
||||
export default [newCases];
|
||||
export default [newCases, newContacts];
|
||||
|
@@ -0,0 +1,41 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New contacts',
|
||||
key: 'newContacts',
|
||||
pollInterval: 15,
|
||||
description: 'Triggers when a new contact is created.',
|
||||
|
||||
async run($) {
|
||||
let offset = 0;
|
||||
const limit = 100;
|
||||
let hasMore = true;
|
||||
|
||||
const params = {
|
||||
operation: 'query',
|
||||
sessionName: $.auth.data.sessionName,
|
||||
query: `SELECT * FROM Contacts ORDER BY createdtime DESC LIMIT ${offset}, ${limit};`,
|
||||
};
|
||||
|
||||
do {
|
||||
const { data } = await $.http.get('/webservice.php', {
|
||||
params,
|
||||
});
|
||||
offset = limit + offset;
|
||||
|
||||
if (!data?.result?.length) {
|
||||
hasMore = false;
|
||||
return;
|
||||
}
|
||||
|
||||
for (const item of data.result) {
|
||||
$.pushTriggerItem({
|
||||
raw: item,
|
||||
meta: {
|
||||
internalId: item.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
} while (hasMore);
|
||||
},
|
||||
});
|
@@ -3,6 +3,8 @@ favicon: /favicons/vtiger-crm.svg
|
||||
items:
|
||||
- name: New cases
|
||||
desc: Triggers when a new case is created.
|
||||
- name: New contacts
|
||||
desc: Triggers when a new contact is created.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
|
Reference in New Issue
Block a user