UserEvent script running on browser? - javascript

I have few questions related to NetSuite:
On the NetSuite help page, the User Event scripts are stated to execute on servers.
In that case if a record is updated in NetSuite indirectly*, it should still trigger the User Event script associated with it, right?
*By indirectly I mean a user does not navigate to the record in a browser and clicks on Edit and Save. An example usecase would be, when a customer payment is made against an Invoice, it updates the Amount due on the Invoice automatically. But it does not trigger the UserEvent Script deployed on the Invoice.
Please let me know if my understanding is correct. Also, could you please give me a way to execute a script when a record is updated both directly and indirectly.
Is there a way to execute a script (make a REST call) when a File is uploaded. I am not able to see it under script deployments for User Event scripts.
Thanks in advance!

The event type that you mentioned, it will not trigger a user event script. Just like the user event script deployed on sales order, it will not be executed when the sales order got fulfilled. Based on my experience changes on the status of a transaction caused by creating another transaction will not trigger UE script. You can deploy a UE script too on Customer Payment record that would process the invoice that is being paid.
File record is not yet supported in SuiteScript. When I say not supported, you cannot deploy a script to it.

1) This is correct yes. You can however select "Execute in commerce context" on your UE script, which means the script will be triggered if a Sales Order is created from outside of NetSuite, on a web store for instance - which is integrated with the NetSuite account.
2) Don't you want to send the file from NetSuite, rather than polling for it from a different system?
You will then need to first load the record as follows in your script(SuiteScript 2.0):
var curRec = scriptContext.newRecord;
curRec = record.load({
type: record.Type.PURCHASE_ORDER,
id: curRec.id,
isDynamic: false
});
curRec will contain all detail of the record.

Related

GTM - Do not fire an HTML tag if the customer refreshes the page

We have currently an order confirmation page on our website after the customer paid where information is sent to our analytics tools.
If the customer refreshes the page, the information about his order is sent again to our analytics tool and then we get wrong/duplicate information in our orders statistics.
Is there an easy way to prevent this?
The goal would be here to not trigger the custom html tag when the customer reloads the page.
It should be only fired once.
Thanks!
Best,
Victor
You can use PerformanceNavigation.type or PerformanceNavigationTiming.type respectively in a Javascript variable to find out if the page has been reloaded (the former is already marked as deprecated while the latter is still marked as experimental, so to be on the safe side you should probably check which one is supported by the browser and use that).
Then use the return value to detect reloads and block the tag depending on that.
An alternative would be to set a cookie or local storage entry with the transaction and block based on that.
We finally found another solution that seems to work: We used an additional trigger in GTM that prevent the info to be sent twice.
When calling the page for the first time, the condition is set to "false", and on each following request to that page it is set to "true".
We made some test orders and it seems to works correctly. Thanks!

I have scripts in one of spreadsheet document and cannot locate the script

Here's I got this email everyday since I created way before a timer based notification of events. I want to delete the script but I cannot found inside the spreadsheet. What I did, I deleted the file itself and empty the trash. Still I got the google failure notification even the host file was not exist. Anyone knows how to remove/report this problem.
Summary of failures for Google Apps Script: spreadsheet_sms_notifier
Your script, spreadsheet_sms_notifier, has recently failed to finish
successfully. A summary of the failure(s) is shown below. To configure
the triggers for this script, or change your setting for receiving
future failure notifications, click here.
Summary:
Error Message Count Authorization is required to perform that
action. 275
Start Function Error Message Trigger End 2/4/18 8:19
AM sendsms Authorization is required to perform that
action. time-based 2/4/18 8:19 AM 2/4/18 8:20 AM sendsms Authorization
is required to perform that action. time-based 2/4/18 8:20 AM 2/4/18
8:21 AM sendsms Authorization is required to perform that
action. time-based 2/4/18 8:21 AM ... ..
As you get a "forbidden" error message (mentioned in a comment) perhaps the email notification refers to an add-on. Try to uninstall it.
Another thing to try is to remove the associated trigger. From https://developers.google.com/apps-script/guides/triggers/installable
To review all of the triggers that are associated with your Google
account and disable the triggers you no longer need, follow these
steps:
Open the script editor by opening any script or visiting https://script.google.com.
Click Edit > All your triggers. If you just created a new script, the script editor will prompt you to give the script a name
first.
A dialog will list every simple or installable trigger that is associated with your account. From this dialog, it is not possible to
determine which script uses a given trigger, but if you recognize the
function name for an installable trigger and know that you don't need
the trigger anymore, you can delete the trigger by clicking the X
icon to the left of the function name. Simple triggers like
onOpen() cannot be disabled from this dialog; instead, you must edit
the appropriate script and remove or rename the onOpen() function.

Need to prompt user for text during NetSuite Workflow

Business logic: when an Approver rejects an expense report, an e-mail must be sent to the creator. This e-mail must contain the reason for rejection.
Existing setup: A multi-state workflow has already been set up, that sends the expense report through two separate approvals. Each Approver can approve or reject the workflow. Rejecting the workflow sends it back to the submission state for correction by the creator. My task is to acquire the rejection text and create the outgoing e-mail.
Obvious solutions rejected:
Send Email workflow action-- this WF action allows only boilerplate e-mails to be sent (with some parameterization). Nothing can be customized from the user's perspective.
Workflow Action Script-- this script context does not allow the use of JavaScript dialog presentations, such as window.confirm() or window.prompt(). There are popup parallels in the workflow action palette, but only for confirm() or alert()-- no prompt(). Unfortunately the technical requirements and restrictions for Workflow Action scripts are horribly documented, so this result was learned only after spending a few days researching and writing the script.
Add a tracking field on the expense report that must be filled in before the report can be Rejected. However, this requires unlocking the record, an issue for Audit concerns. It also must be made visible and hidden for appropriate states, and can be adjacent to only one set of action buttons.
The new state is not an end-state, so e-mail generation is not automatic as it is for end-states. We just want similar functionality.
The only other possiblity I see is to target a new page, such as a Suitelet. However, I only need a single string from the user. A Suitelet seems overkill, plus it makes the workflow more complicated to go back to the correct report.
Any insight or ideas that anyone might have would be most helpful.
Well, I've tried several other solutions and none of these seem to work:
Redirect (via nlapiSetRedirectURL() in a WFA script) on state Exit trigger to a Suitelet that takes the parameters passed from the workflow where the user enters the rejection text; then redirect to the expense report. This fails because the report state does not actually change.
Do the same thing, but from the Entry trigger of the new state. Requires some more detailed parameter handling but this also does not work. Apparently redirecting from any part of the UI experience cancels the workflow transition.
Setting the "User Interface" context on the workflow action also does not work; the redirection still kills the transition.
The nlapiTriggerWorkflow() function also does not seem to have an effect, even when the UI context is set on the action. No errors or debug text generated.
The user may just have to accept manual behaviors like, adding a note and sending a canned e-mail. This appears to be a major feature hole, either deliberate or not. Note that there is a Confirm and a Show Message action, but no Prompt. So why not? No details, just deal with it I guess.
Final solution:
A separate workflow state where a script runs. A new button on the workflow redirects to this new state.
A workflow action script in these special state(s) that has parameter settings that are changed depending on where they are in the workflow. This script redirects to the suitelet (next), which interrupts the workflow transition and keeps the item in the same state.
A suitelet that takes the user text in a textarea, and a non-submit action button. Don't want to use a submit button, because that reloads the same page, creating an extra step.
A client script that takes parameters from the suitelet button event, creates the e-mail, and redirects back to the original record (that is in the same workflow state as before).
Of course this is inelegant. The user must press a button to create the e-mail, and a separate button to transition to the correct state. It fulfills the user's needs, but it requires them to remember to press one button to create the e-mail reason text, and another button to actually reject the record.
The need for this convoluted solution is because of all the roadblocks in NetSuite design:
Can't prompt for text from a server-side WF action script. We can confirm() giving a Y/N (Ok / Cancel) answer, but somehow string returns are not allowed.
Can't complete a transition if a WF action script redirects to another page.
Suitelet submit buttons reload the same page, so we need a client script to do the final e-mail creation work.
Feature hole much?
There is a limitation on the workflow that it cannot accept input from the user. Hence, we need to go ahead with a customized solution for this scenario. I have implemented this in multiple NetSuite projects. Here is the solution which works
(1) Have a workflow action script which would call the suitelet. Please see script sample below for workflow action script
define(['N/record','N/runtime','N/redirect'],
function (record,runtime,redirect){
function callSuitelet(context)
{
try {
var currentRecord = context.newRecord;
var vendorId = currentRecord.id;
var vendorNumber = currentRecord.getValue('entityid');
redirect.toSuitelet({
scriptId: 'customscript_call_rejection_reason',
deploymentId: 'customdeploy_call_rejection_reason',
parameters: {'recid':vendorId,'vbTransactionNo':vendorNumber, trantype: context.newRecord.type}
});
}
catch (err) {
log.error("Error while calling Suitelet", err);
throw err;
}
}
return {
onAction: callSuitelet
};
});
(2) Have a suiteLet designed to capture the "Rejection Reason"
(a) Add a field on the suitelet form labelled as "Rejection Reason" (FieldType.TEXTAREA)
(b) Add a "Submit" button which will add the data to the transaction record
(c) Redirect the suitelet back to the transaction record once "submit" button is clicked
This should solve the problem stated above

Dynamics CRM - call javascript resource

We are in the process of migrating our data to CRM online.
I would like to run some javascript code that I have that creates the sharepoint folder for an entity when the page loads.
However as we are using an api to create the record from existing data, is there a way to call/trigger the javascript on record create?
There is no hook for JavaScript with Dynamics CRM to trigger an action when a record is created, however the following may work (although is a little messy!).
1) Create a new dummy field (hidden, but on every the form) called "SharePoint Created?", this is a two options field, default value of "No".
2) Create a new JavaScript function to execute on "Form Load", which checks the form type to ensure its in edit mode (not create), if so, checks the value for the "SharePoint Created?" field, if this field is "No", update it to "Yes", call your SharePoint creation function, then save the record.
The better option would be to the move the call to a Plugin, which can be executed on create of a record, but understand authentication is always a problem.

Javascript OnPageUnload - on "leave page" must call additional method

This is the problem: my web application (php) has a wizard feature which gathers customer's data page by page, and stores it in session. If customer tries to navigate away from the page before they have completed the wizard, I would like to display a massage to the effect of "You will lose your data". If the customer chooses to navigate away, the session data should be wiped.
I know that I can intercept this action by binding onpageunload event, but is there a way to then make another call, e.g. ajaxClearWizard() if the customer says "yes"?
PS I can see that, perhaps session shouldn't be used here, but I'm using an existing library, and although this wizard-data-persistence used to be a required feature the business now requires it to be removed :(
Any ideas, alternatives?
Thanks in advance!
window.onbeforeunload = function () {
return 'Your content has not been properly saved yet!';
};
This will make the browser display a confirmation box in middle with above content.

Categories

Resources