NetSuite beforeload cancel action - netsuite

I have a userevent beforeload that conditionally removes print buttons. If users are in the list view they are still able to print from that menu. So I was wondering if anyone knows of a way to either intercept the request and redirect or notify them, or even change which pdf template is used.
Here is my code snippet:
if (scriptContext.type === scriptContext.UserEventType.PRINT) {
if(status == 2){
log.debug({
title: 'Trying to Print Approved PO',
details: status
});
return true;
}
else{
log.debug({
title: 'Trying to Print UnApproved PO',
details: status
});
//code here to redirect users, notify them of issue or change to different pdf template
return false;
}
}

While not ideal, I just threw an error and didn't catch it.
throw 'This error is a result of trying to print a PO that has not been approved.';

You can add checkbox field on the UE beforeLoad event and set the value true/false if the user can/can't generate the pdf. Then control the new field on the freemarker AdvPDF and instead of print the content, you can show a message if the user can't generate the pdf.
var field = objForm.addField({
id: 'custpage_allow_access',
type: serverWidget.FieldType.CHECKBOX,
label: 'Allow access'
});
field.defaultValue = "F";
field.updateDisplayType({
displayType: serverWidget.FieldDisplayType.HIDDEN
});

Related

Q: NetSuite E-Commerce - Source Custom Entity Fields to Reference Checkout

I have a custom entity field placed inside NetSuite, now I have to source the value of this field to my Reference Checkout as I'll use the value as a condition for which payment method to show on the shop.
Any ideas how to do this? I've searched the SuiteAnswers and got no significant help there.
Thank you!
I've looked into using view.model.get('customfield ID here') but it has not worked. I've also already defined the field on models.js. Just not sure if I placed it properly.
Render function of Order Wizard Payment Method Selector
, render: function()
{
if (this.wizard.hidePayment())
{
this.$el.empty();
this.trigger('change_label_continue');
return;
}
if (!this.selectedModule)
{
var selected_payment = this.model.get('paymentmethods').findWhere({primary: true})
, selected_type;
var creditlevelhold = this.wizard.model.get('creditlevelhold'); < -- this is the custom field
console.log(creditlevelhold);
if(selected_payment){
selected_type = selected_payment.get('type');
}
else if(this.wizard.options.profile.get('paymentterms') && creditlevelhold === ''){
selected_type = 'invoice';
}
this.setModuleByType(selected_type)
Should be available like:
this.wizard.model.get('options')['custbodyxxx']

Make Suitescript run on data imported via a .csv upload

I wish to do .csv import, and have my suitescript run on that data, as if a user was inputting the data from the UI.
define(['N/currentRecord'],
function(currentRecord) {
function saveRecord (){
var objRecord = currentRecord.get();
var imagescheck = objRecord.getText('custitem_imagescheck');
var live=false;
if (imagescheck=='T' ){
live=true;
}
else {live=false;}
objRecord.setValue({
fieldId: 'custitem_live',
value: live,
});
return true;
}
return {
saveRecord: saveRecord
};
}
);
So if I imported the value "True" to the field custitem_imagescheck, the suitescript should act as if the user checked the checkbox and turn the field "custitem_live" to "True".
At the moment, the above code only work via the UI, not during .csv import.
When you go through the CSV Import Wizard, on the second page you will see Import Options and under the standard radio button choices you will see Advanced Options. Expand the Advanced Options and look at the bottom right where you will see a check-box for the option to "Run Server SuiteScript and Trigger Workflows". Select this option to run User Event scripts etc when you import.

Microsoft Bot framework session.endDialog() use

I read the Bot document somewhere people posted if you replace dialog then previous dialog store in stack and stored somewhere.
Now I tried to follow the way to endDialog() then replaceDialog();
callRequest.GetWebAPICall(session, urlData, function (body) {
if(body.statusCode == 200) {
if(body.data == undefined) {
builder.Prompts.choice(session,Want to Select List?", "Yes|No",{listStyle: builder.ListStyle.button});
} else {
session.endDialog();
session.replaceDialog('/Show List');
}
} else {
session.send('Something went wrong. You can use the back or top command.');
session.replaceDialog('/menu');
}
});
For need to know if I replace below lines
session.endDialog();
session.replaceDialog('/Show List');
by
session.endDialog('/Show List');
No. endDialog() doesn't have the functionality to start a new dialog. You can refer to the function definition interface endDialog(message?: TextOrMessageType, ...args: any\[\]): Session;.
In your case, '/Show List' would be sent to the user as a message.
And there is also a misunderstanding about replaceDialog().
Ends the current dialog and starts a new one its place. The parent dialog will not be resumed until the new dialog completes.
If you need to store the previous dialog, you can use beginDialog()

Write the plugin when Selecting the lookup flied and according to filed selection Show/Hide Address filed in form.....?

We Have Contact Entities in contact Entitie one lookup filed company Name in that lookup having two values 1.Account and 2.Contact . When we are selecting contact show the address filed when we select account hide the address filed we needs to write the plugin to Execute that works. Kindly any one help me on the same.
Thanks!!
Rajesh Singh
First, if you need to make change on a form, you can't use plug-ins. Plug-ins are made for bussinees logics, like Update another record when the first one is created, make complex logic, etc...
What you need it is a javascript that executes on the OnLoad of the form and OnChange event in that OptionSet.
The lines you are looking for are:
function ShowField()
{
// The field is present on the form so we can access to its methods
var optionSet = Xrm.Page.getAttribute("custom_attribute");
if (optionSet == undefined)
{
return;
}
// The control is present on the form so we can access to its methods
var controlAddress = Xrm.Page.getControl("custom_address");
if (controlAddress == undefined)
{
return;
}
var valueOptionSet = optionSet.getValue(); // This is the value you set creating the OptionSet
switch (valueOptionSet)
{
case 0: // Your account value, show
controlAddress.setVisible(true);
case 1: // Your contact value, hide
controlAddress.setVisible(false);
default:
return;
}
}
You need to register a web resource and register the event, if you need more information about the code or why this stuff is here and why this not just tell me.

NetSuite Sublist/child record does not update/refresh in edit mode

If the form I am on is in edit mode, and I add items to the sublist (A child custom record) via my suitescript I can not get the list that is visible to the customer to refresh/update.
I have attempted to use the following command, but then found that it only works on a static / read only list.
// Refresh the package contents list
nlapiRefreshLineItems('recmachcustrecord_myCustomRecord');
Is there a way to force a sublist/child record to update its view when the parent transaction form is in edit mode?
On my form I have clicked my "Do Something" button which is to create child records. After the records are created the transaction form does not update the sublist. When I exit edit mode the form then realizes the new lines and displays them.
Thank you,
You may have other fields on the record that are not saved yet.
In order to do what you want you'd have to save the record and reopen it with your script.
Here is an example from Netsuite help of saving and reopening a record:
try
{
//committing the phone call record to the database
var callId = nlapiSubmitRecord(call, true);
nlapiLogExecution('DEBUG', 'call record created successfully', 'ID = ' + callId);
//Redirect the user to the newly created phone call
nlapiSetRedirectURL('RECORD', 'phonecall', callId, false, null);
}
catch (e)
{
nlapiLogExecution('ERROR', e.getCode(), e.getDetails());
}

Resources