I apologize if this is a dumb question, but I am new to NetSuite, and have noticed that their documentation is absolutely ridiculously horrifyingly and atrociously disgusting. All humor and bitterness aside though, I can't find the details that should exists in SuiteAnswers. I can find the type Field or Record, but it doesn't show me the options available for those types. It just shows what methods to call to return a field or record.
So I have it on the fieldChanged event as the training specifies, and below is what I have.
function fieldChanged(context) {
debugger;
var customer = context.currentRecord
if (context.fieldId == 'custentity_apply_coupon') {
var field = record.getField("custentity_apply_coupon");
if (record.getValue("custentity_apply_coupon") == true) {
reord.getField("custentity_coupon_code").isDisabled = false;
}
else{
reord.getField("custentity_coupon_code").isDisabled = true;
}
field.isDisabled = false;
}
}
Turns out that, and I never found this in the documentation, that once you get the field from currentRecord.currentRecord, you can set it to disabled via field.isDisabled. Took me forever to find out that isDisabled was a property of field, and then took a complete guess to see that isDisabled was a get/set call for ClientSide Scripts. Below is the code that ended up working.
function fieldChanged(scriptContext) {
var customer = scriptContext.currentRecord;
if(scriptContext.fieldId == "custentity_sdr_apply_coupon"){
debugger;
var field = customer.getField("custentity_sdr_coupon_code");
field.isDisabled = !customer.getValue(scriptContext.fieldId);
if(field.isDisabled){
customer.setValue(field.id, "");
}
}
}
I hope this will help.
function fieldChanged(context) {
var currentRecord = context.currentRecord;
var approvalChkBox = currentRecord.getValue({
fieldId: 'supervisorapproval'
});
var memoField = currentRecord.getField("memo");
if (approvalChkBox)
memoField.isDisabled = true;
else
memoField.isDisabled = false;
}
Thats a good question, this is the simplest solution you are looking for. use getValue method and isDisabled to meet this requirement. the code is self explanatory. Good Luck.
function fieldChanged(context) {
var record = context.currentRecord;
var fieldname = context.fieldId;
var changedValue = record.getValue(fieldname); //getValue method is the key here
var couponid = record.getField('custentity_kld_coupon_code');
if (fieldname == 'custentity_kld_apply_coupon' && changedValue == true) {
couponid.isDisabled = false; //isDisabled helps you to enable or disable a field
} else {
couponid.isDisabled = true;
}
}
Totally agree. I think the SuiteScript 2.0 Student Guide could've been more helpful if they included a preview of their codes along the way.
For anyone else who is still following along, this code below worked for me. Thanks for everyone else that contributed in this post. Used your codes to create this too. I also included some other codes from the previous exercises (i.e. displaying a message when entering 'x' into the coupon code).
/**
* #NScriptType ClientScript
* #NApiVersion 2.0
*/
define([],
function() {
function fieldChanged (context) {
var customer = context.currentRecord;
if(context.fieldId = 'custentity_sdr_apply_coupon') {
var check = customer.getValue('custentity_sdr_apply_coupon');
var code = customer.getField('custentity_sdr_coupon_code');
if (check == true){
code.isDisabled = false;
} else {
code.isDisabled = true;
}
}
}
function saveRecord(context) {
var customer = context.currentRecord;
var empCode = customer.getValue('custentity_sdr_coupon_code')
if(empCode == 'x') {
alert('Invalid code value. Please try again');
return false;
}
return true;
}
return {
fieldChanged: fieldChanged,
saveRecord: saveRecord,
};
});
var objRec_Curr = scriptContext.currentRecord;
var TransferType = objRec_Curr.getCurrentSublistValue({sublistId:'xxxxxxxxxx', fieldId : 'xxxxxxxxxxxx'});
if(TransferType == 'ABC')
eval("nlapiDisableLineItemField('custpage_sublist_out', 'custpage_out_transfer_location', true)");
else
eval("nlapiDisableLineItemField('custpage_sublist_out', 'custpage_out_transfer_location', false)");
Related
I'm currently using this package Excel 1.1.5 ... It currently has a method called save but it just returns a List integers...and I don't know where to go from here..
List<int>? potato = excel.save(fileName: 'namePotato');
Hoping you guys can help!
Thanks!
Found the answer, you can use dart:io and I've also used Permissions_handler
Future exportReport() async {
var excel = Excel.createExcel();
DateTime _now = DateTime.now();
String _name = DateFormat('yyyy-MM-dd').format(_now);
String _fileName = 'surname-' + _name;
List<int>? potato = excel.save(fileName: _name);
PermissionStatus status = await Permission.storage.request();
if (status == PermissionStatus.granted) {
await File('/storage/emulated/0/Download/$_fileName.xlsx').writeAsBytes(potato!, flush: true).then((value) {
log('saved');
});
} else if (status == PermissionStatus.denied) {
log('Denied. Show a dialog with a reason and again ask for the permission.');
} else if (status == PermissionStatus.permanentlyDenied) {
log('Take the user to the settings page.');
}
return null;
}
I am trying to hide a field when a checkbox is checked in an Opportunity but the script I have is throwing a ReferenceError - Context is not defined.
Here is my code:
define(['N/currentRecord','N/search', 'N/format'],
function(currentRecord, search, format) {
function pageInit_disableMyText(scriptContext) {
console.log('START : here you will be able see logs via console (F12 on browser)');
var recCurrent = context.currentRecord; //This represents your current loaded record, you can get the values of the fields here
var myCheckbox = recCurrent.getValue('custbody7'); //This is the code for getting the value of your field
console.log('myCheckbox Value is : ' + myCheckbox);
if(myCheckbox == true)
{
//get the field and disable it
fld1 = recCurrent.getField('custbody3');
fld1.isDisabled = true;
}
else
{
//if you didn't set the field to be disabled by default, then you don't need the code to enable it here
//since it runs only once when the page loads
}
}
function fieldChanged_toggleBox(scriptContext) {
//Different function that triggers on change of a field value, can use this to toggle the checkbox
var currentFieldID = context.fieldId;
console.log('context.fieldId : '+ currentFieldID);
//Check which field is toggled
if(currentFieldID == 'custbody7')
{
//Essentially do the same as above
var recCurrent = context.currentRecord;
var myCheckbox = recCurrent.getValue('custbody7');
if(myCheckbox == true)
{
//get the field and disable it
fld1 = recCurrent.getField('custbody3');
fld1.isDisabled = true;
}
else
{
//Now you need code to enable it as you are toggling the disabling and enabling it realtime
fld1 = recCurrent.getField('custbody3');
fld1.isDisabled = false;
}
}
}
//this is the retrun statement where we declare the script type to implement
return {
pageInit: pageInit_disableMyText,
fieldChanged: fieldChanged_toggleBox
};
});
When I use devtools in Chrome it shows the error on this line:
var recCurrent = context.currentRecord; //This represents your current loaded record, you can get the values of the fields here
But I cannot see what the problem is.
Any help is appreciated.
Thanks!
The parameter name in your function is scriptContext , change it to context
function pageInit_disableMyText(scriptContext) { // <---- Change this parameter to context
Basically you can call it whatever you like, but then you have to use the same variable.
I'm working on an Archiving Application with this code in it:
var arcName:String = "Archives/" + aDBName + "-Backup-" + toDay + "-" + thisTime.slice(0,5);
var server:String = appDB.getServer();
var arcDB:NotesDatabase = appDB.createCopy(server, arcName);
arcDB.setTitle("This is a Test");
but it fails at the arcDB.setTitle - the new copy of the Database is created so there is no issue to that point.
This is from the IBM Knowledge base:
var db2:NotesDatabase = db.createCopy(null, "names2");
db2.setTitle("Copy of names");
I can't see the difference between these two pieces of code.
Am I missing something?
Usually when something doesn't work with XPages that relates to database or design objects the first thing I check is the Maximum Internet Name and password Access https://stackoverflow.com/a/23045860/1187943
Or change so I do the work using sessionAsSigner or sessionAsSignerWithFullAccess
If you don't care about the effectiveUser's access to the source database, their permissions to make a copy, and their access rights to create a NotesDatabase on the target Domino server, I'd absolutely second Fredrik's suggestion to use sessionAsSigner/WithFullAccess.
Additionally, I find it's best practice to use try/catches (helps with troubleshooting and errorHandling), object testing (.isOpen() when accessing a NotesDatabase), and returning an Object that can be read by the calling function.
Here's some example code that might help:
var copyNotesDatabase = function(dbName) {
var isSuccessful = true;
var responseMessage = "";
try {
//set appDB using dbName from function arguments
var appDB = session.getDatabase(session.getServerName(),dbName);
//var appDB = sessionAsSigner.getDatabase(session.getServerName(),"sourceDb.nsf");
//var appDB = sessionAsSignerWithFullAccess.getDatabase(session.getServerName(),"sourceDb.nsf");
if(appDB.isOpen()) {
var arcName:String = "Archives/" + aDBName + "-Backup-" + toDay + "-" + thisTime.slice(0,5);
var server:String = appDB.getServer();
//arcDB will be created based on appDB permissions, ie effectiveUser, or sessionAsSigner, etc.
var arcDB:NotesDatabase = appDB.createCopy(server, arcName);
if(arcDB.isOpen()) {
arcDB.setTitle("This is a Test");
responseMessage = "Successfully copied NotesDatabase!"
} else {
isSuccessful = false;
responseMessage = "Unable to open copied NotesDatabase.";
}
} else {
isSuccessful = false;
responseMessage = "Unable to open source NotesDatabase.";
}
} catch(e) {
print("Error from SSJS: " + e);
isSuccessful = false;
responseMessage = e;
}
return { status : isSuccessful, message : responseMessage };
}
With this function, you could do something like this:
function makeCopy(appName) {
var fObj = copyNotesDatabase(appName);
if(fObj.status) {
return "Successfully copied " + appName;
} else {
return fObj.message;
}
}
... at the very least, using a try/catch and returning your error will at least tell you why your current code isn't working. Hope this helps!
function clickButtonHandler(event:MouseEvent):void
{
var message:Object = new Object();
message.text = txtMessage.text;
message.userName = txtUser.text;
//Posts to this swf
showMessage(message);
//Posts to ALL OTHER swf files..
group.post(message);
}
function showMessage(message:Object):void
{
output_txt.appendText(message.userName+": "+message.text + "\n");
}
function jsalertwindow(event:MouseEvent):void
{
var alert:URLRequest = new URLRequest("javascript:alert('Please enter your User name')");
navigateToURL(alert, "_self");
}
As you can see there are two function which are contain mouseevent. I want to send those function with an if-else statement. If user write something in text input component which name is txtUser and,
send_btn.addEventListener(MouseEvent.CLICK, clickButtonHandler);
will work, else(if the user forget writing anything)
send_btn.addEventListener(MouseEvent.CLICK, jsalertwindow);
will work.
And one more question should i use MouseEvent.CLICK or MouseEvent.MOUSE_DOWN? Thanks for your advice.
Assign a single handler to the button click (MouseEvent.CLICK is the right event to use) and check the field is populated in the handler:
function clickButtonHandler(event:MouseEvent):void
{
var message:Object = new Object();
// Check the field is populated
if (txtUser.text != "")
{
message.text = txtMessage.text;
message.userName = txtUser.text;
showMessage(message);
//Posts to ALL OTHER swf files..
group.post(message);
}
else
{
// Nothing in the input field, show the alert
showAlert();
}
}
function showMessage(message:Object):void
{
output_txt.appendText(message.userName+": "+message.text + "\n");
}
function showAlert():void
{
var alert:URLRequest = new URLRequest("javascript:alert('Please enter your User name')");
navigateToURL(alert, "_self");
}
I’ve tried the ‘hook’ as shown below and found in other posts:
ExecuteOrDelayUntilScriptLoaded(function()
{
var oldGanttControl = SP.GanttControl;
SP.GanttControl = function()
{
oldGanttControl.call(this);
var oldInit = this.Init;
this.Init = function(jsGridControl, jsRawGridData, params)
{
oldInit.call(this, jsGridControl, jsRawGridData, params);
DoCustomizations(jsGridControl);
};
};
},"SPGantt.js");
Function DoCustomizations(grid)
{
//etc etc
}
However this seems to work only for SP2010. With SP2013 I get an error saying:
“SCRIPT438: Object doesn’t support property or method ‘WaitForGanttCreation’
sp.ui.timeline.debug.js, line 3335 character 13″
Is there a solution for this to work on a Gantt View in SP2013 ?
Any help would be greatly appreciated.
Try that:
ExecuteOrDelayUntilScriptLoaded(function()
{
var oldGanttControl = SP.GanttControl;
SP.GanttControl = function() {
oldGanttControl.call(this);
var oldInit = this.Init;
this.Init = function(jsGridControl) {
oldInit.apply(this, arguments);
DoCustomizations(jsGridControl);
};
for (prop in oldGanttControl) {
if (oldGanttControl.hasOwnProperty(prop)) {
SP.GanttControl[prop] = oldGanttControl[prop];
}
}
};
},"SPGantt.js");
Function DoCustomizations(grid)
{
//etc etc
}