twentyhq / twenty

Building a modern alternative to Salesforce, powered by the community.
https://twenty.com
GNU Affero General Public License v3.0
15.02k stars 1.48k forks source link

Return only updated fields of records in zapier update trigger #6071

Open martmull opened 1 week ago

martmull commented 1 week ago

Client voice

In Zappier I could set up only trigger that on any change it notifies me. But I want to configure on specific events or tasks.

We do have a trigger update record in zapier, but it returns all record field, so it is not possible to get what fields were updated

We need to find a way to send updatedFields info, probably by adding a field updatedFields in data in packages/twenty-server/src/engine/api/graphql/workspace-query-runner/jobs/call-webhook-jobs.job.ts based on args provided in the query in packages/twenty-server/src/engine/api/graphql/workspace-query-runner/workspace-query-runner.service.ts Then we should update what Zaps gets from webhooks data, today it get the data.record key which contains all the record -> see here packages/twenty-zapier/src/utils/triggers/triggers.utils.ts

greptile-apps[bot] commented 1 week ago

To return only updated fields of records in the Zapier update trigger, follow these steps:

  1. Modify perform function in triggers.utils.ts:

    • Locate the perform function.
    • Add logic to filter and return only the updated fields of the records.
      export const perform = async (z, bundle) => {
      const records = await getRecords(z, bundle);
      return records.map(record => {
         const updatedFields = {};
         for (const key in record) {
             if (record[key] !== bundle.inputData.previousRecord[key]) {
                 updatedFields[key] = record[key];
             }
         }
         return updatedFields;
      });
      };
  2. Adjust trigger_record.ts to use the modified perform function:

    • Ensure the trigger uses the updated perform function from triggers.utils.ts.
      
      import { perform } from './triggers.utils';

    export default { key: 'record_updated', noun: 'Record', display: { label: 'Record Updated', description: 'Triggers when a record is updated.' }, operation: { perform, // other properties } };

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. [Edit Issue Bot Settings](https://app.greptile.com/apps/github)