Changing question --- From a user event script, wh...
# suitescript
s
Changing question --- From a user event script, what is the best way to create a new record so that other user event scripts for that record are triggered? I have an SO ue script creating an IF and I need the IF user event scripts to trigger.
s
Am I right to understand you have a UE on SO, and a UE on the IF? UE doesn't trigger UEs. That's a NetSuite rule.
s
It's triggering the user event when the item fulfillment is created. I see it in the logs that it ran
s
what context is your IF UE running on? That's the one setting the values right?
s
Let's just say that the item for film it scripts aren't triggered when an item for filming is Created from a user event script on a sales order. Outside of sending it to a suitelet to trigger, how would you trigger the item fulfillment script
It is running under all contacts
s
workflow action scripts can trigger UEs, I'm not sure what you mean with
Copy code
Let's just say that the item for film it scripts aren't triggered when an item for filming is Created from a user event script on a sales order.
Outside of sending it to a suitelet to trigger, how would you trigger the item fulfillment script
s
Ok, you are correct. It was the logs from deleting the IF lol. So, what would be the best way to trigger Item Ful. scripts when an Item Fulfil is created from a sales order user event?
s
probably change the IF to a WFA script that runs on entry under a specific condition. For example, the SO UE can check a checkbox, and the IF WFA can pick up the SO and only run on the checkbox checked true.
s
I'd prefer to not do a workflow. Is there a way, without having to pass in auth info, to call a restlet/suitelet from a user event script?
s
consider pushing one side or the other to a background script such as scheduled if possible. Doing so much in a user event will damage the user experience.
s
Yes, the only fear I'd have is if it errored, there would be no immediate information to the user that it did not work correctly
Also, this could be triggered 5 times at once
m
Calling a suitelet from a user event is a pretty common practice @screnshaw The suitelet needs to be set to available without login, and the calling script has to call the external url. This allows downstream user events on the created record to fire (because they are created from a suiltelet not a UE)
s
Thanks, so I will need to add code to get the authentication then, or can this be done without having to generate the auth header info?
s
I have to say matt's suggestion is NOT a common practice for us, given the security issues and again the perf penalty
m
A suitelet available without login does not need an auth header.
b
do whatever item fulfillment logic you want to do in a in the sales order user event script instead
m
Yes, that approach is definitely preferred if you can get away with it.
s
matt, in order to call a suitelet from a user event script, do I have to make it available without login?
m
Often, those downstream IF user evens are bundled offerings or something that you can’t just absorb though.
b
preferably with a custom module, though laziness will probably let you use the same script file in both
s
@battk Yes I could do that, but I'd have to re-arrange things as this is a shared file. Or I could just make sure the file is in production so it doesn't error if another part of it gets deployed
I have the logic already separated into a business logic file, so it is already a custom module fortunately
m
That’s the way to go then. More performant, less risk of impacting your concurrency or experiencing network timeouts, and no security concerns.
👍🏼 1
s
For future me, if I were to want to transform a record in a suitelet, does the suitelet HAVE to be without login?
m
No - if you’re calling it from a client script, you can call the internal URL and the user’s session and role are automatically passed in the request.
s
But from a user event script you do?
m
If you’re calling it server-side, there is no session to leverage and maybe not even a user, so you’d need to call a restlet and pass in authentication details like a token. Might be possible with a suitelet but sounds like a real PITA to find out.
s
haha. Ok, I'll keep that in mind. Thanks everyone! MAN, I wish netsuite would give us a "triggerUserEvent" flag.
b
https.requestRestlet is the other option
c
Workflow action scripts will also trigger UEs if needed.
I use suitelets via client script all the time
So if the IF process doesn't have to be part of the UE, you could also give them a button to click to create them
👍🏼 1