Suite Script for User Event is not getting triggered for xedit operaration - netsuite

I have a SuiteScript which is getting triggered on AfterSubmit of any Case update. It is working fine for normal updates.
But when I try to edit a Case in-line(through case search), the event is not getting triggered.
Do I need to configure anything specific to handle the in-line edit during the script deployment?
Please find the script which I am using to identify the xedit operation.
function handleSupportCaseCreateUpdateReqeust(type, form, request) {
try {
if(type == 'xedit'){
nlapiLogExecution('AUDIT', 'TFSNSIntegrator Log', 'Type of the event is :'+ type);
}
} catch (e) {
nlapiLogExecution('ERROR', 'Exception', e.message);
}

This is a simple thought, but may as well check - have you confirmed that your Deployment's Log Level is set to Audit? If not, that could be why you aren't seeing that in the execution log.

Through NetSuite Support, I figured out the issue.
The issue was with the option I selected to deploy the SuiteScript. I selected 'Edit' event to trigger the script, since we dont have a option "xedit". Actually we should not select any particular event. I just deployed it with our selecting any specific event and it started to work.
Thanks all for your replies!

Related

cypress binding to custom events

I need cypress to stub or spy some function after some custom event is fired (that is happening before window:onload) like jQuery.ready event
cy.on('window:jQuery:ready', (win)=> {
win.console.log("Jquery is ready")
})
this being within individual test never being executed. Any help would be highly appreciated

How do I add button in NetSuite client script and use it as trigger for script function?

I'm trying to add a button to the current record with the Client Script button definition on a script record, but for some reason it's not finding my function. I'm returning my function tryThisand there is a button on the page which I created on the script record with the function tryThis defined in the appropriate field, but the code doesn't run. Here's my script:
define (['N/currentRecord','N/search','N/record'] ,
function(currentRecord,search,record) {
function tryThis(context){
log.debug({
title: 'try this',
details: 'try this'
});
}
function pageInit(context) {
}
return {
pageInit: pageInit,
tryThis: tryThis
};
});
Nothing happens :(
Yes, the script is deployed.
How can I use this button on a client script??
This doesn't exactly answer your question directly, but I hope it may help. I tested this, and there appears to be nothing wrong with the way you've set it up - the only thing that seems to be not working is the log module, which I've come across before in client scripts.
Try running your function using a console.log() or alert() instead (both work for me).
Hopefully someone with more detailed knowledge of the N/log module's design and behavior will chip in, as the documentation seems to indicate that this should work.
At the bottom of your Client Script record in Edit mode you will find where you can easily set the button and function to call.

Prevent record deletion with SuiteScript

I want to prevent a record from being deleted based on certain conditions in NetSuite. However, I can't seem to find a failure event on validation? BeforeSubmit on a UserEvent has a delete type, but it doesn't have a return value for the function, so I can't just say return false, can I?
How do I then prevent the deletion of a record, or fail a record submission of a certain type?
Instead of returning false, just throw an error. Not user friendly but it is the only option, as far as I know.
Since it is in the Before Submit User Event, the submission or deletion will fail.
You'll want to use a beforeSubmit user event script and throw an error using nlapiCreateError. Here's an example:
function beforeSubmit(type) {
if(type == 'delete') {
// NOTE `nlapiGetFieldValue` returns nil/empty during a delete event
// `nlapiGetOldRecord` needs to be used to pull the entire record
var payment = nlapiGetOldRecord();
if(payment.getFieldText('paymentmethod') == 'cash') {
throw nlapiCreateError(
'AN_ERROR',
'Message to the user!',
true
);
}
}
}
You can also use a Workflow to prevent the Delete button to display to the user:
You could add client-side code to pop up a message to the user when trying to delete a record you want to prevent. With that said, you would still want to put a UserEvent script preventing the delete actions as well. This would prevent the user from by passing the restriction

Why won't my suitescript deploy scripts fire?

I don't know when this started, but I think it happened after I did some refactoring using the IDE with renaming.
Anyway, if I attach the script through the form, they fire. However, my user event, nor client scripts fire though there is a deployment record. That deployment record uses the same script that works IF it is attached via the form custom code area.
What happened?
EDIT:
For Instance:
Trying to add a button to opportunity:
function userEventBeforeLoad(type, form, request){
var list = form.getSubList("item");
list.addButton('custpage_customconfigurebutton', 'Configure', 'clientStartConfigurator()');
}
Upload Script
Add to "Script"
Deploy:
It never fires when I "Create Opportunity"?
NONE of my user event scripts are firing
EDIT 2 (NEW SCREENS as requested
Following lines of code working for me
function userEventBeforeLoad(type, form, request) {
//nlapiLogExecution('error', 'type', type);
var list = form.getSubList("item");
list.addButton('custpage_customconfigurebutton', 'Configure',"alert('Hello World')");
}
I suspect you might have an error in your clientStartConfigurator(). To verify, you can also use the browser console on click of your button to see whether you're successfully returning from your respective function or not.
Hope this will help you.

"immediate_failed" - Could not automatially log in the user

I have a problem when I developed my website with Google+ sign-in:
I did step by step that the doc told me but I always failed at step4:
https://developers.google.com/+/web/signin/
the result was always ""immediate_failed" - Could not automatially log in the user", I just don't kown why, can anyone help me, thanks very much! :-(
Note that in the sample code you pointed to, the "immediate_failed" check is commented out. This is intentional, since the first time a user encounters the Sign-in button on the page, it will fail.
The reason it fails is that when the page first loads, before the user even presses the button, a request is sent to Google to determine if the user has already logged in (via Google or another site, for example). If they are - there is no need for them to log in again, so the button never needs to be shown. But if they have not been logged in already, you will get the "immediate_failed" response, and will need to either show (or not clear) the button.
tl;dr - Don't worry aout getting immediate_failed when the page first loads. This is normal.
As a workaround I use gapi.auth.authorize method in the gapi.auth.signIn callback. Here is my code:
gapi.auth.signIn({
'callback': gPlusLoginCallback
});
function gPlusLoginCallback(authResult) {
if (authResult['status']['signed_in']) {
doSmth(authRes['access_token']);
} else if (authResult['error'] == "immediate_failed") {
gapi.auth.authorize({
client_id: gplusClientId,
scope: 'https://www.googleapis.com/auth/plus.login email',
immediate: true
}, function (authRes) {
if (authRes['status']['signed_in']) {
doSmth(authRes['access_token']);
}
});
}
}
function doSmth(accessToken){
//Do smth
}
Change this setting "immediate: true", to be false " immediate: false".
But if you like to make more complex implementation look at the first sample here https://developers.google.com/api-client-library/javascript/start/start-js. You have to calls to Google's "gapi.auth.authorize({...", the first one with "immediate: true", and the second one with "immediate: false".
The question is old but I faced this issue recently.
In my case, it was because I specified the URI parameter prompt to none. I guess Google doesn't like that if the user has never been logged to your platform before.
Whenever I changed that to consent or totally removed it, it worked great.
In my case, the error was because of explicitly specifying the authorization parameter prompt to 'none',similar to a previous answer.
It worked for me by specifying prompt=None or as per the official docs,you may skip this parameter.

Resources