How to run a script on actual creation - netsuite

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).

Related

Send an email (using flow) when the text field changes in PowerApps

I have a PowerApps App which is linked to a SharePoint List. When the user makes some changes to the text field in the app; I want the flow to send the user an email regarding the update.
I've been trying to track the SharePoint List entry and see if the entry is modified, then send an email. But so far I'm unable to do so.
I've been able to send an email when a text field changes to a specific text; but I'm looking for something where a particular entry in the list is changed.
When an item is created or modified > Condition (Column is equal to Yes) > Send email based on the condition
You don't need Powerapps for the same, what I mean is you need Flow for this.
Create and Run your flow on SharePoint directly.
In your flow check whatever your field is changed, if changed then you can send the user email.
You do not need to depend on Powerapps, Flow can alone work for this scenario.
Ensure you are using the Sharepoint When an item is created or modified Trigger in Power Automate (the tool formerly known as Flow)
Add a Trigger Condition for the column in question. Something along the lines of #triggerBody()?.Status,'Pending')
Trigger Conditions are not very well documented at the moment, but provide a powerful way to control when a Power Automate runs.

Avoid local changes after replication

I have a Notes application that is used offline on a local replica most of the time.
Users can create and update documents.
On the server, an agent processes all new documents.
The idea is that - once the agent processed the documents - the users are no longer allowed to update the documents.
In general, this is quite simple to setup by setting author access on the documents processed by the agent.
But, because users work on the local replica and the agent runs on the server, this scenario is possible:
user creates document offline
replication of document (creating of doc on server)
agent runs on server / user updates document locally
replication of document (updating author access locally / updating changes on server) ==> Causes save conflict or inconsistent data
Is there a way to make sure that the user can no longer update a document once it is replicated to the server.
Or is there a way to force the agent to run on replication and immediately replicate the access update?
I was thinking of creating a button the user can click to replicate/update all documents, but to avoid users that forget to click the button, I prefer the default replication settings to make sure everything is replicated when possible.
When I investigated a few years ago replication does a "pull", then a "push", so doing something on the server won't work. There are a couple of options.
A separate "flag" document which server processing updates, instead of updating the actual document. This would allow for updates causing a second set of processing.
Store a config document / environment variable with the last replicated date, and check against that in the Form's queryModeChange and queryOpen (if editMode). You can then prevent editing if the document was created before the last replicated date.
Instead of using Author fields for the "wrong" reason, I'd add a non-editable Status field, with values like "Initial", "Ready", and all the rest you might need. Then, replication should be set up differently, using a formula that only replicates documents with Status!="Initial". The user might have 2 buttons to save a document: one just saves to the local database and the other also changes the status to Ready. Once Status="Ready", the user can no longer modify the document.
By the way, did you set document replication to "Merge conflicts"? You might reduce the number of conflicts considerably.
One alternative would be to set up the form so that the user never actually saves the document locally. Instead, the document is emailed to the server where an agent triggered by mail delivery performs the actual update. When the agent is done with the update, it sends an email back to the user telling him/her that the updates are available and instructing them to replicate in order to retrieve them. If the Notes client is actually being used for email, you can probably even put a button into the email and say "Click here to replicate and open your document".

Plugins for incoming and outgoing emails in CRM 2011

I need to create two plugins for CRM 2011
Whenever an email is incomging or outgoing I need to check if the email has any attachments in it. If yes I need to set one boolean value to true.
When user (user only, not workflow or automatic message etc.) answers some email I need to fire a plugin that checks incident's status (email is regarding to an incident) and depending on the status do some things.
I'm not really familiar with this whole email tracking concept. We have an email router configured, but that's all I can say.
What are the steps that I need to use in order to achieve plugins described?
For the first plugin I think "Create of email" is enough, right? What about the second plugin and how can I make sure that plugin is fired only when a real person sends an email?
For the first plugin:
To check for attachments for an email you will need to create a plugin which executes on create of the ActivityMimeAttachment entity, which is the entity which stores email attachments.
When an inbound email is processed by the Email Router (or tracked in the Outlook Client) the parent Email record is created first, and then an ActivityMimeAttachment record is created for each attachment.
If you try to check for attachments when an Email is created it will be executing before any attachments are created. However, you may also need a plugin to execute when an Email is created to set the 'Has Attachments' field to false.
The plugin on ActivityMimeAttachment will need to get the parent email activity and set the 'Has Attachments' field to true. This will handle both inbound and outbound emails.
Also note that for 100% accuracy you may need to consider the scenario of a user who is writing an email and adds an attachment, and then deletes it. This could be handled by a plugin running when attachments are deleted, but that logic can get complex (what if two attachments were added but only one was deleted?)
There is some useful sample code for dealing with the ActivityMimeAttachment entity here.
For the second plugin:
A plugin which executes on update of an email would then need to validate the following criteria:
The email direction is outbound (a user has answered an email, e.g. sent a reply)
The email status reason is Sent (the email has actually been delivered and is not saved as a draft)
The email sender and/or owner and/or created by is a real user (filter out automatic and workflow sent emails)
The regarding object is an incident
Then you can implement the required custom validation and logic.
The second item could potentially be achieved using a standard workflow, depending on how complex the custom logic is. If the logic is too complex for a standard workflow, a custom workflow activity might also be useful since additional logic or validation could be added without writing additional code.
For the 1. Plugin: Register on email create and on update (maybe users create the mail first and then update some attachments later)
For the 2. Plugin: Check the following:
plugin context depth should be 1 (this makes sure that no mail created by another plugin is processed)
Check the created by and created on behalf by fields on the email entity to be a non technical users and that no one is acting on behalf of another user creating this mail
Check that regarding object points to incident
If this is not sufficient enough and the users sends mails only via CRM Web GUI you can additionally set a special flag on the record via javascript to make sure that the mail was created using the gui. Than check this status flag in the plugin.

Triggering User Event after creating a record in SuiteScript

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

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