https://netsuiteprofessionals.com logo
s

screnshaw

04/08/2022, 2:57 PM
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

Sciuridae54696d

04/08/2022, 3:02 PM
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

screnshaw

04/08/2022, 3:05 PM
It's triggering the user event when the item fulfillment is created. I see it in the logs that it ran
s

Sciuridae54696d

04/08/2022, 3:06 PM
what context is your IF UE running on? That's the one setting the values right?
s

screnshaw

04/08/2022, 3:06 PM
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

Sciuridae54696d

04/08/2022, 3:08 PM
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

screnshaw

04/08/2022, 3:15 PM
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

Sciuridae54696d

04/08/2022, 3:20 PM
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

screnshaw

04/08/2022, 3:42 PM
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

Shawn Talbert

04/08/2022, 3:46 PM
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

screnshaw

04/08/2022, 3:47 PM
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

mattdahse

04/08/2022, 3:53 PM
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

screnshaw

04/08/2022, 3:53 PM
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

Shawn Talbert

04/08/2022, 3:54 PM
I have to say matt's suggestion is NOT a common practice for us, given the security issues and again the perf penalty
m

mattdahse

04/08/2022, 3:58 PM
A suitelet available without login does not need an auth header.
b

battk

04/08/2022, 3:58 PM
do whatever item fulfillment logic you want to do in a in the sales order user event script instead
m

mattdahse

04/08/2022, 3:59 PM
Yes, that approach is definitely preferred if you can get away with it.
s

screnshaw

04/08/2022, 4:00 PM
matt, in order to call a suitelet from a user event script, do I have to make it available without login?
m

mattdahse

04/08/2022, 4:00 PM
Often, those downstream IF user evens are bundled offerings or something that you can’t just absorb though.
b

battk

04/08/2022, 4:00 PM
preferably with a custom module, though laziness will probably let you use the same script file in both
s

screnshaw

04/08/2022, 4:00 PM
@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

mattdahse

04/08/2022, 4:02 PM
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

screnshaw

04/08/2022, 4:05 PM
For future me, if I were to want to transform a record in a suitelet, does the suitelet HAVE to be without login?
m

mattdahse

04/08/2022, 4:17 PM
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

screnshaw

04/08/2022, 4:18 PM
But from a user event script you do?
m

mattdahse

04/08/2022, 4:19 PM
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

screnshaw

04/08/2022, 4:20 PM
haha. Ok, I'll keep that in mind. Thanks everyone! MAN, I wish netsuite would give us a "triggerUserEvent" flag.
b

battk

04/08/2022, 4:27 PM
https.requestRestlet is the other option
c

creece

04/08/2022, 4:28 PM
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