Hi all, I have a question. I have an MR script whe...
# suitescript
c
Hi all, I have a question. I have an MR script where I’m retrieving custom records from a search and need to create a payload to send to the integration for creating or updating these custom records. How can I determine in the MR script whether the custom record is being created or updated? Is it safe to rely on the date created and last modified fields to identify create and update scenarios? The only issue I can think of is if the record is created and updated within the same minute, which could cause a problem. Any thoughts?
a
From an integration design perspective, you should not need to worry about that. You can simply send your payload, and the other end should be able to tell if the record exists on their end and update it or create it if not. The only thing you may need to worry about on your side(NetSuite) is whether or not you should send the payload at all.
But if your integration endpoint have different methods to handle CREATE or UPDATE then you may need to worry about those, the use of the Last Modify Date and Created Date is good enough for that purpose.
👍 1
c
That’s absolutely correct but the integration payload has Create and Update parameters which I need to send them for every create or update request.
@alien4u When I tried to get the datetimemz it always gives seconds as 00. Example 123000 AM. The problem here, if the create and update happens at the same time my logic will fail
a
Another thing you can try is to make the search using the system notes instead of the record itself.
b
usually apis tell you the id of the created record, which you can store on the custom record
so usually you can tell the difference between create and update, you shouldnt rely on last modified date for this purpose
sadly updating the id also updates the last modified date, so you end up doing a create and an update, which is unfotunate
if you want to overengineer a solution, its possible to create a child record with the custom record as the parent
which allows you to associate an id with a record without actually updating it
at the cost of making it more annoying to get at that id
other solutions are things like a user event script to check or uncheck a checkbox to determine if a record should be exported, which allows you more control on which updates should be ignored