SuiteScript Design – The (Good) Man-in-the-Middle

Update: A helpful reader wrote in and said their team calls these “Jumplets”, and I have since lovingly adopted this name for the pattern described here. You can also find example code here.

One of the more frustrating limitations when building SuiteScript systems is that User Event scripts do not trigger each other. Take an exceedingly common use case where there is a User Event on the Sales Order which automatically transforms the Sales Order into an Invoice. Chances are, there are also User Events deployed to the Invoice, but none of those will be triggered by our Sales Order User Event.

RAWR! This can be extremely frustrating when building complex systems involving chains of records. The limitation exists for good reason: it would be incredibly easy to – either accidentally or intentionally – create an infinite loop of User Events going back and forth triggering each other, essentially locking out any other processing.

There is, however, a design pattern you can use to work around this limitation. I call it the “Suitelet Man-in-the-Middle”, although I should probably come up with something else to call it given the baggage that phrase carries in our space. (I’m open to suggestions, reply with yours!)

User Events do not chain together, but record actions performed by Suitelets do trigger User Events. Thus, instead of our Sales Order User Event creating the Invoice directly, we can instead create a back-end Suitelet (i.e. a Suitelet with no UI components) that will do our Invoice creation for us.

The Sales Order User Event sends a request to the Suitelet with any relevant data (usually a record ID will suffice), the Suitelet receives the data from the Sales Order, transforms it into an Invoice, and saves the Invoice. When the Suitelet saves the Invoice, any User Events and Workflows deployed to the Invoice will trigger as well.

Wherever you want to trigger sequential User Events, you can insert a back-end Suitelet in between each pair of User Events (hence the pattern’s name), and the chain of User Events will happily go on as long as you want them to.
HTH

-EG

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Related posts

January 7, 2021

Anything I wrote today about business would both feel and be inadequate. I simply can’t arrive at the words to express how I feel in this moment. So instead, here are a few helpful ...

Read More

December 20, 2020

2020 was a hundred swift kicks to the shorts and one giant kick in the ass. If you’ve lost people you love, if you’ve gotten sick or hurt, if you’ve lost your job, if ...

Read More

December 16, 2020

“I’ve been meaning to learn SuiteScript, but it’s hard to find the time …”“We’re slammed, and I just don’t have the time …”“I haven’t made the time …” All are variations of a theme ...

Read More

December 14, 2020

Last week we looked at mimicking the functionality of a REST endpoint with its own module (e.g. retrieving a User, or a list of Users, refreshing a token, etc). For complex integrations that rely on a large ...

Read More