Hello, so I’m a total newbie to automation and I rely heavily on Gemini or GPT for coding guidance. Here’s my goal: I’m getting opportunities from pipelines via an HTTPS request (previous node) and I need to count them by status for a weekly tally. Can someone break down this GPT-generated code for me or offer some tips to simplify the process? Thanks a ton!
Hey @stonewall you’re on the right track, but the loop issue is causing it to only process the first record. Try iterating directly over the opportunities array like this
const opportunities = $json.opportunities;const statusCounts = {};
for (const opp of opportunities) {const status = opp.status;statusCounts[status] = (statusCounts[status] || 0) + 1;}
return [{ json: statusCounts }];
This way, each opportunity is counted correctly, and you’ll get an object with the totals for each status.
Oh I see, yeaah I thought the input.first part is important, I guess not . Thank you so much I’ll try it! But is there another thing I need to map or is the code above the only thing needed? But Thank you very much for this!
No need to map anything else, the code above should do the trick. Just plug it in and test it out. If you need to handle any specific edge cases or add more functionality, feel free to ask. Otherwise, you’re good to go!