I would like to hide the ID 'custrecord_hrx_vendor_status_list'
once item has selected in select box ( options ).
Here is my code.
/**
* #NApiVersion 2.x
* #NScriptType ClientScript
*/
define(['N/ui/serverWidget', 'N/error'],
function (error) {
function fieldChanged(context) {
var currentRecord = context.currentRecord;
var fieldId = context.fieldId;
if( fieldId === 'custrecord_hrx_negotiation_type' ){
var selectedType = currentRecord.getText(fieldId);
console.log(currentRecord.getField('custrecord_hrx_vendor_status_list'));
currentRecord.updateDisplayType({
id: 'custrecord_hrx_vendor_status_list',
displayType: serverWidget.FieldDisplayType.HIDDEN
});
}
}
return {
fieldChanged: fieldChanged
}
}
);
----HERE IS THE ERROR
As the error message says, you are trying to load a module that is not available. You are writing a client script, and trying to load a module that is only for server-side scripts.
Additionally, N/currentRecord#CurrentRecord does not have a updateDisplayType() method.
The way to hide a field in a SS2.0 client script is:
currentRecord.getField({
fieldId: 'custrecord_hrx_vendor_status_list'
}).isDisplay = false;
N/ui/serverwidget Module doen not work in client script.you must use like this to hide currentRecord.getField( { fieldId: id } ).isDisplay = false;
Related
I tried this above, here I am getting a null value only from my previous record.
Kindly give some guidance to solve my questions.
thanks in advance.
/**
*#NApiVersion 2.0
*#NScriptType UserEventScript
*/
define(["N/url", "N/record", "N/runtime"], function (url, record, runtime) {
function afterSubmit(context){
var recordobj = context.newRecord;
var prevItemrecord= context.oldRecord;
var Itemname = recordobj.getValue({fieldId:'itemid'});
var prevItemname = prevItemrecord.getValue({fieldId : 'itemid'});
var Type=context.type;
var checkbox=recordobj.getValue({fieldId:'custitem17'});
if(Type== context.UserEventType.CREATE)
if((Itemname=prevItemname+'-c')&&(checkbox=true))
record.submitFields({
type: recordobj.type,
id: recordobj.id,
values:{custitem_item_link:prevItemname}
});
}
return{
afterSubmit:afterSubmit
}
});
This is my code
On create there is no old record.
Since you are trying to update the same record as was just created you are better off having this in a beforeSubmit event script
if((Itemname=prevItemname+'-c')&&(checkbox=true)) this is an error
if((Itemname == prevItemname+'-c') && checkbox) is more what you need
If you are trying to capture a copy operation you can set that up in the beforeLoad event that you use in the beforeSubmit event.
function beforeLoad(ctx){
if(ctx.type == ctx.UserEventType.COPY){
if(ctx.form){
ctx.form.addField({
id:'custpage_original_item',
label:'Copied Item',
type:ui.FieldType.SELECT,
source:'item'
}).updateDisplayType({
displayType:ui.FieldDisplayType.HIDDEN
}).defaultValue = ctx.request.parameters.id;
// your naming makes me wonder if you are trying to link to the
// source item rather than just saving a reference to the source
// item's name
/*
* Using the original item's name like below is closer to what you
* posted but I think by the time the script runs the itemid field
* has been cleared.
* ctx.form.addField({
* id:'custpage_original_item_name',
* label:'Copied Item Name',
* type:ui.FieldType.TEXT
* }).updateDisplayType({
* displayType:ui.FieldDisplayType.HIDDEN
* }).defaultValue = ctx.newRecord.getValue({fieldId:'itemid'});
*/
}
}
}
function beforeSubmit(ctx){
if(ctx.type == ctx.UserEventType.CREATE){
const itemRec = ctx.newRecord;
if(itemRec.getValue({fieldId:'custitem17'})){
const sourceId = itemRec.getValue({fieldId:'custpage_original_item'})
if(sourceId){
itemRec.setValue({
fieldId:'custitem_item_link:prevItemname',
value:sourceId
});
/* or use a search function to look up the original item's name
* and then test the new item's name.
*/
}
}
}
}
I am wanting to display lot numbers on item fulfilment and invoices.
I don't have any scripting ability... sadly...
So I implemented this script and it works really well.
https://jcurvesolutions1.zendesk.com/hc/en-us/articles/4711971574425-Remove-Bin-Number-from-item-inventorydetail-When-Printing-with-Advanced-PDF-Templates
/**
* #NApiVersion 2.x
* #NScriptType UserEventScript
* #NModuleScope SameAccount
*/
define(['N/record'],
function(record) {
function beforeSubmit(scriptContext) {
var rec = scriptContext.newRecord;
var lines = rec.getLineCount({sublistId:'item'});
var tempS = '';
for(var i=0;i<lines;i++){ // for each line
var subList = rec.getSublistSubrecord({
sublistId:'item',
fieldId:'inventorydetail',
line:i
});
if(subList.getValue('id')){ //if the line has inventory details
var sublistLines = subList.getLineCount({
sublistId:'inventoryassignment'
});
for(var j=0;j<sublistLines;j++){ //for each line of the inventory details
tempS+=subList.getSublistText({
sublistId:'inventoryassignment',
fieldId:'issueinventorynumber',
line:j
});
if(j<sublistLines-1) tempS+='\n';
}
rec.setSublistValue({
sublistId:'item',
fieldId:'custcol_tb_lot_no_via_js',
line:i,value:tempS
});
tempS='';
}
}
}
return {
beforeSubmit: beforeSubmit
};
});
However I have one issues with it.
In our Netsuite account I have it set up so that Invoices display items that are on Backorder.
However backorder items don't have "inventory detail" so when I try and edit or save the invoice I get the following error.
{"type":"error.SuiteScriptError","name":"USER_ERROR","message":"Invalid number (must be positive)","stack":["anonymous(N/serverRecordService)","beforeSubmit(/SuiteScripts/DisplayLot# Packing Slip.js:16)"],"cause":{"type":"internal error","code":"USER_ERROR","details":"Invalid number (must be positive)","userEvent":"beforesubmit","stackTrace":["anonymous(N/serverRecordService)","beforeSubmit(/SuiteScripts/DisplayLot# Packing Slip.js:16)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false}
It is due to one of the lines not having any inventory detail as it is on back order.
so what I am asking is if some kind person could tell me what I need to change in the above script so that it ignores backorder items.
Thanks.
To ignore backordered line items, you must get the back ordered quantity per line item. In my UI I see the field id "backordered", however in the NS records browser the field id is "quantityremaining". See which works for you.
var backOrderedQty = rec.getSublistValue({sublistId: 'item', fieldId: 'backordered', line: i}); //or try field id quantityremaining
then evaluate if it is equal to 0. If it is, then do not proceed with code for this line. If it is, then do proceed. Example:
if(backOrderedQty == 0) {
//do nothing
} else {
//do something
}
In your code, you already have a check for if the line has inventory details. So we can add this check for back ordered quantity to the same if statement and we do not need an else statement, since we want to "do nothing".
Full code, with modified lines not indented:
/**
* #NApiVersion 2.x
* #NScriptType UserEventScript
* #NModuleScope SameAccount
*/
define(['N/record'],
function(record) {
function beforeSubmit(scriptContext) {
var rec = scriptContext.newRecord;
var lines = rec.getLineCount({sublistId:'item'});
var tempS = '';
for(var i=0;i<lines;i++){ // for each line
//get the current lines backordered qty
var backOrderedQty = rec.getSublistValue({
sublistId: 'item',
fieldId: 'backordered', //or quantityremaining
line: i
});
var subList = rec.getSublistSubrecord({
sublistId:'item',
fieldId:'inventorydetail',
line:i
});
if(subList.getValue('id') && backOrderedQty ==0){ //if the line has inventory details AND back ordered qty is 0
var sublistLines = subList.getLineCount({
sublistId:'inventoryassignment'
});
for(var j=0;j<sublistLines;j++){ //for each line of the inventory details
tempS+=subList.getSublistText({
sublistId:'inventoryassignment',
fieldId:'issueinventorynumber',
line:j
});
if(j<sublistLines-1) tempS+='\n';
}
rec.setSublistValue({
sublistId:'item',
fieldId:'custcol_tb_lot_no_via_js',
line:i,value:tempS
});
tempS='';
}
}
}
return {
beforeSubmit: beforeSubmit
};
});
Most examples involve calling a client script in suitelet and then the suitelet button calls a function in client script. I was wondering if u can write the button function in suitelet instead.. is it possible?
This is because I want to run n/task module which cannot be used in a client side script and has to be used in the suitelet.
An example would be appreciated, thanks.
use the form.addSubmitButton. when clicked it works on the post action and the task module can be used.
You might also want to call a suitelet directly per your original question. If you want to avoid a client script just to have a function to call you can do:
/**
* #NApiVersion 2.x
* #NScriptType UserEventScript
*/
define(["N/log", "N/search", "N/url"], function (log, search, url) {
function beforeLoad(ctx) {
var form = ctx.form;
log.debug({ title: 'before load with ' + ctx.type, details: null });
if (ctx.type == ctx.UserEventType.VIEW) {
var ffRec = ctx.newRecord;
if (ffRec.getValue({/* some logic that requires the action */})) {
var orderStatus = search.lookupFields({
type: 'salesorder',
id: ffRec.getValue({ fieldId: 'createdfrom' }),
columns: [
'statusref'
]
}).statusref[0].value;
if (orderStatus.indexOf('pendingBilling') != -1) {
var suiteletURL = url.resolveScript({
scriptId: 'customscript_my_script',
deploymentId: 'customdeploy_my_script',
returnExternalUrl: true
});
form.addButton({
id: 'custpage_button_1',
label: 'My Action',
functionName: '(function processRebill(){window.location.href=\"'+ suiteletURL + '&custparam_ff=' + ffRec.id + '\";})'
});
}
}
}
}
return{
beforeLoad : beforeLoad
}
});
I am trying to write a script that will create a new transfer order from a sales order, copying all of the lines in the process. I have the script written, but I am getting an error that "define" is not defined. This script is modified from another script, so it is possible that I missed something. I am new to scripting, so I would appreciate any help and could do without criticism (even if my script is complete garbage).
/**
***************** ALEM ********************
* After Submit User Event script running on Sales Orders. Generates a TO.
* Version Date Author Remarks
* 1.0 9 Jan madams Initial Create
*/
/**
* #NApiVersion 2.0
* #NScriptType UserEventScript
* #NModuleScope Public
*
*/
define(['N/record',], function (record) {
function afterSubmit(context) {
if(context.type == 'delete'){
log.debug('Exiting script', '...');
return;
}
try{
var so = record.load({
type:'salesorder',
id:context.newRecord.id
});
var so_items = so.getLineCount({sublistId:'item'});
// Create new Transfer Order if Record is On Create.
var to_record = record.create({
type:'transferorder',
isDynamic:true
});
to_record.setValue({fieldId:'customform', value:136});
to_record.setValue({fieldId:'class', value:so.getValue('class')});
to_record.setValue({fieldId:'transferlocation',
value:so.getValue('location')});
setLineItemsOnTO(so_items, to_record, so);
to_record.setValue({fieldId:'custbody_related_record',
value:context.newRecord.id});
so.setValue({fieldId:'custbody_related_record',
value:to_record.save()});
so.setValue({fieldId:'orderstatus',value:'B'});
so.save({ignoreMandatoryFields:true});
} catch(e){
log.debug('Error Loading Record' + context.newRecord.id, e);
return;
}
}
return {
afterSubmit: afterSubmit
}
function setLineItemsOnTO(so_items, to_record, so){
for(var i=0; i<so_items; i++){
to_record.selectNewLine({sublistId:'item'});
to_record.setCurrentSublistValue({
sublistId:'item',
fieldId:'item',
value:so.getSublistValue({
sublistId:'item',
fieldId:'item',
line:i
})
});
to_record.setCurrentSublistValue({
sublistId:'item',
fieldId:'quantity',
value:so.getSublistValue({
sublistId:'item',
fieldId:'quantity',
line:i
})
});
to_record.commitLine({sublistId:'item'});
}
}
});
Did NetSuite import the script as SuiteScript 2.0? It probably imported the script as SS1.0.
The comment block containing #NApiVersion 2.0 needs to be the first comment block in the file. NetSuite looks for that block only at the top of the file to identify SS2.0 scripts.
I built a form with suitelet, that has a sublist, dropdown and a button. After user would tick some selections on the sublist, a button is pressed and the selected items are sent via rest elsewhere.
Suitelet:
#NApiVersion 2.x
*#NScriptType Suitelet
*/
define(['N/ui/serverWidget', 'N/search', 'N/https', 'N/record'],
function(serverWidget, search, https, record) {
function onRequest(context) {
if (context.request.method === 'GET') {
var form = serverWidget.createForm({ ... });
form.clientScriptModulePath = 'path/to/client/script';
// code to build a sublist, add a button and write page
} return {
onRequest: onRequest
};
});
Then, my clientscript is something like:
* #NApiVersion 2.x
* #NScriptType ClientScript
*/
define(
[ 'N/currentRecord', 'N/https' ],
function(currentRecord, https) {
functionSendRequest(sublist //the sublist that I want to get from the suitelet)
{
//code to build json string and send http request
} return {
saveRecord: test
}
});
Now, after spending a number of hours on this, a N/currentRecord came to my attention (I'm noobie with netsuite) and it would've seem as a problem solver for me, as it retrieves records that are currently active in client-side context. It works for great for dropdown menu and has a method getSublist(options), though it returns record.Sublist which has only getColumn() method. Thus, it won't really work for me. So, is there a way to pass sublist parameter to the clientscript from the suitelet once a button is pressed?
To solve your problem you could use getSublistValue from currentRecord like this:
var currentRec = currentRecord.get();
var numLines = currentRec.getLineCount({
sublistId: 'item'
});
var sublistFieldValue = currentRec.getSublistValue({
sublistId: 'item',
fieldId: 'item',
line: 3
});
If you really want to pass something from the Suitelet to the clientside function you gotta set your button this way:
var someTextToPassToTheClientscript = 'The Suitelet send its regards';
form.addButton({
id : 'custpage_some_button',
label : 'MyButton',
functionName : 'functionSendRequest("' + someTextToPassToTheClientscript + '")'
});
And then have your clientscript receive it like this:
/*
* #NApiVersion 2.x
* #NScriptType ClientScript
*/
define(
['N/currentRecord', 'N/https'],
function (currentRecord, https) {
functionSendRequest(textReceivedFromSuitelet) {
//code to build json string and send http request
}
return {
functionSendRequest : functionSendRequest
}
});