This topic was automatically generated from Slack. You can find the original thread here.
Hi looking for idea on how I can retrieve a value from a previous step - basically I am pulling history from Xero API in previous step - this will return a varying amount of return_values - some may be 4 some maybe 15 - however I want to find the latest return value that has “Invoice sent” as the text (Some have Reminder sent or Approved as the text)- I then want to retrieve that return Value date UTC string and store as a value i can use in the next step. Picture shows that it was sent twice in this instance and I only need to retrieve the ‘latest value’ ie History records no 4 - any help appreciated
Hi looking for idea on how I can retrieve a value from a previous step - basically I am pulling history from Xero API in previous step - this will return a varying amount of return_values - some may be 4 some maybe 15 - however I want to find the latest return value that has “Invoice sent” as the text (Some have Reminder sent or Approved as the text)- I then want to retrieve that return Value date UTC string and store as a value i can use in the next step. Picture shows that it was sent twice in this instance and I only need to retrieve the ‘latest value’ ie History records no 4 - any help appreciated
To achieve this, you can use a code step in your Pipedream workflow to filter and find the latest “Invoice sent” record from the history returned by the Xero API. Here’s an example of how you can do this: // Assuming the history data from the Xero API is stored in a variable called `historyData` const historyData = [ // Your history records here ]; // Filter the records with "Invoice sent" text const invoiceSentRecords = historyData.filter(record => record.text === "Invoice sent"); // Sort the records by date in descending order (latest first) invoiceSentRecords.sort((a, b) => new Date(b.dateUtc) - new Date(a.dateUtc)); // Get the latest "Invoice sent" record const latestInvoiceSent = invoiceSentRecords[0]; // Store the date UTC string of the latest record for use in the next step const latestInvoiceSentDateUtc = latestInvoiceSent.dateUtc; Now you can use latestInvoiceSentDateUtc in the next step of your workflow. Make sure to replace historyData with the actual data returned from the Xero API step in your workflow.
Sure! Here’s the code you provided converted into a Pipedream component using defineComponent: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { historyData: { type: "string[]", label: "History Data", description: "The history data returned from the Xero API", }, }, async run({ $ }) { // Filter the records with "Invoice sent" text const invoiceSentRecords = this.historyData.filter( (record) => record.text === "Invoice sent" ); // Sort the records by date in descending order (latest first) invoiceSentRecords.sort( (a, b) => new Date(b.dateUtc) - new Date(a.dateUtc) ); // Get the latest "Invoice sent" record const latestInvoiceSent = invoiceSentRecords[0]; // Store the date UTC string of the latest record for use in the next step const latestInvoiceSentDateUtc = latestInvoiceSent.dateUtc; // Return the latest invoice sent date return { latestInvoiceSentDateUtc }; }, }); Make sure to replace historyData with the actual data returned from the Xero API step in your workflow. You can use the latestInvoiceSentDateUtc in the next step of your workflow.
I apologize for the confusion. It seems there might be an issue with the data or the code. To help you better, can you please provide the sample data from the Xero API step? This will help me understand the structure of the data and adjust the code accordingly.
Thank you for providing the sample data. Based on the data structure, I’ve updated the code to find the latest “Invoice sent” record and retrieve the ‘DateUTCString’ value: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { historyData: { type: "string[]", label: "History Data", description: "The history data returned from the Xero API", }, }, async run({ $ }) { // Filter the records with "Invoice sent" text const invoiceSentRecords = this.historyData.filter( (record) => record.Changes === "Invoice sent" ); // Sort the records by date in descending order (latest first) invoiceSentRecords.sort( (a, b) => new Date(b.DateUTCString) - new Date(a.DateUTCString) ); // Get the latest "Invoice sent" record const latestInvoiceSent = invoiceSentRecords[0]; // Store the date UTC string of the latest record for use in the next step const latestInvoiceSentDateUtc = latestInvoiceSent.DateUTCString; // Return the latest invoice sent date return { latestInvoiceSentDateUtc }; }, }); Now you can use latestInvoiceSentDateUtc in the next step of your workflow. Make sure to replace historyData with the actual data returned from the Xero API step in your workflow.