Triggering User Event after creating a record in SuiteScript - netsuite

I could swear this worked a few versions back, but now it doesn't seem to.
My script creats a new Customer record, and I have a User Event (After Submit) deployed on the Customer record.
I've tried setting the record mode to be dynamic - even tried setting the sourcing to true, however, I can't seem to get the User Event to trigger after I create the record.
Here's a sample of what my script looks like, as you can see, it's quite simple:
var customerRecord = nlapiCreateRecord("customer", {recordmode: "dynamic"});
customerRecord.setFieldValue("companyname", "test company");
nlapiSubmitRecord(customerRecord, true, false);

From the NetSuite Help page titled What are User Event Scripts?:
User event scripts cannot be executed by other user event scripts. You
can, however, execute a user event script from a call within a
NetSuite scheduled script, a portlet script, or a Suitelet.
I am not sure if this is due to a recent release or not, but this could be why it is no longer working.

Is the script that is creating the Customer record a User Event script also? If yes, then a User Event script cannot trigger another User Event script. NetSuite does not allow this.

You are right, I am also facing the same problem.
After so many trials I find out that you cannot trigger user event from another user event. And 1 more thing, you can also not trigger any workflow attached to the record from user event.

You can not trigger a User Event Script from a user event script, but you can call a Suitelet within your User Event Script that you can use to trigger the other User Event Script to run.
This is shown here: https://videohub.oracle.com/media/SuiteScript+2.0+%26gtB+User+Event+Script+to+Trigger+another+User+Event+Script+using+Suitelet/1_vgt8ud6n

Related

SuiteScript 2.0 detect change on custom field with client script

I deployed a client script that handles a click event on a custom button. When I click the button, I may an api call to get data and the field is populated with the data. This part works great, but when I go to save the new information on the record, I get this alert:
The record has not changed. Do you really want to submit it?
Is there some way to trigger a form changed event or something similar?
try setWindowChanged(window,true)

NetSuite SuiteScript 2.0 user event email event type

When creating a script deployment, one of the possible event types is "Email". However, if I choose this even type and send an email (via the communication tab) no user events are triggered. Is it possible to trigger a user event script before an email is generated (beforeLoad)?
If there are reason that you don't just run your User Event script, with the email module, and send the necessary email from that script? I may be missing what you are actually trying to accomplish.

User event not firing on create event

I'm having a strange problem, where a user event, made to fire for sales orders on the Create event type, is not starting at all for some of them.
Trigger on: BEFORE SUBMIT FUNCTION
STATUS - Released
EVENT TYPE - Create
LOG LEVEL- Error
EXECUTE AS ROLE - Full Access
All access boxes are checked.
The only pattern I've found so far is that all failures are being created by a Script (Scheduled), which makes little sense to me...
Has anyone found a similar issue??
Do you want the scheduled script to trigger the user event script? Do you have the "All Roles" checkbox checked? I believe you need this to be checked for the UE script to be execute when the scheduled script creates a record.
You might want to check your scheduled script if it is error free. One possible reason why the user event script is not running is because the scheduled script has an error. Run your scheduled script first from the script debugger to see if there are errors.

How to run a script on actual creation

I'm trying to find out how to run a script to edit a record before the it's actually called by the user. So far all events seem to be handled when there is some kind of interaction with the record.
This is to be able to automatically send emails with the customer's information upon creation.
Write into NS DB > Script updates user data and sends email > First view/edit is made.
Seems the previous admin managed using UE on beforeload, but that is not working anymore.
nlapiGetNewRecord().getId() --> returns an id not belonging to the record.
Any ideas how to trigger a script on creation?
Based on your requirement to send an e-mail on record creation, I don't see where the record editing takes place.
Though if you do want to edit the record just before it is created, you can use beforeSubmit(type) in a User Event script and have it run when type == "create".
Otherwise if no editing is needed, afterSubmit(type) in a User Event script and have it run when type == "create" should work just as well.
If I understand your requirements, the editing code(assuming based on what you are saying that you are trying to edit the record that is created) should be written in a beforeRecordSubmit and the email sending should be done in afterRecordSubmit. This way you know the data you want to enter is written to the database correctly (brs) and the email is only sent if the record commits in the database correctly (afs).

Drupal time based triggers

I'm building an event signup system and integrating it with Ubercart. Each event is a product and has a price and a start time.
I wish to be able to trigger an action one week before the event starts. The action is supposed to send an email to the users that bought the event and perform a capture on the registrant's credit card. But where do I define the action and how do I trigger it one week before event start?
I assume you're talking about Drupal 6, since you're mentioning ubercart. Does the action to send the email you're takling about already exist?
If it does, you can assign it under Site Building | Triggers | Cron. If it doesn't show up in the list of actions, you might need the Triggerunlock module.
If the action doesn't exist, you're going to have to write the PHP code to send the emails and do the calculations. You will need to create your own module and either use hook_cron, or create a custom action.

Resources