I am creating a custom coded action which displays the difference between the ‘Became MQL date’ & the ‘Became Opportunity date’ properties in full days. I don’t seem to understand why my code does not work. Check the spoiler for the code.
It’s difficult to say exactly what the issue might be without more context. One thing to check is whether the event object has an object property that has an objectId property. If either of these is null or undefined, it will cause an error when you try to access them.
Additionally, if the contact object does not have a properties property, or if the hs_lifecyclestage_marketingqualifiedlead_date or hs_lifecyclestage_opportunity_date properties are null or undefined, it will cause an error when you try to access their value property.
You might want to consider adding some error handling to your code to catch and handle these possible errors. For example, you could add a try-catch block around the code that attempts to access the event.object.objectId and contact.properties properties, and add appropriate error handling logic within the catch block.
Also while the math for the differenceInDays variable looks correct, the number will come out as a decimal, I would suggest you round that final number.
Let me know if this helps, and with a little more context I think we can solve this.
Also I wrote out this same formula in nodejs but I assume you’re wanting it in python