Say I have the following snippet, which is basically a form with a button attached to it. On click, I want to execute a function:
define(['N/ui/serverWidget', 'N/search', 'N/https'],
function(serverWidget, search, https) {
function onRequest(context) {
if (context.request.method === 'GET')
{
var form = serverWidget.createForm({
title: 'Some Form'
});
// some code
form.addButton({
id : '_buttonId',
label : 'Button Label',
functionName: "someFunctinonIWantToCallOnClick(myParam)"
});
context.response.writePage(form)
} else {
// some other code
}
}
function someFunctinonIWantToCallOnClick(myParam)
{
// some code
}
return {
onRequest: onRequest
};
});
According to the NetSuite's documentation:
options.functionName
string
optional
The function name to be triggered on a click event.
Version 2016 Release 1
What am I doing wrong?
There are a number of things wrong with your example.
you are not actually writing the form. Eventually you need:
context.response.writePage(form);
Your function you want to call is only on the server. It is not defined on the client. You need to include a client script that has that function:
form.clientScriptModulePath = './myFormClient.js';
Related
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 have below code. How can i cover in the Jest salesforce?
testhandle(event) {
let testAbr = event.target.text;
if (testAbr) {
this.dispatchEvent(new CustomEvent('testpasss', { detail: { type: 'specilsnumber', input: testAbr } }));
}
}
this is coming on the click of user from UI. onclick={testhandle}
you can do a query of the markup element on which you have added the onclick handler method, and then dispatch a custom event on that element.
Example:
element.shadowRoot.querySelector('.hasOnclick').dispatchEvent(new CustomEvent('click'));
Make sure to add test assert in promise.resolve() to handle asynchronous DOM updates as below:
return Promise.resolve().then(() => {
expect(value).toBe(expected);
});
I am trying to do begindialog from another another dialog js file. I am getting error.
<b>[onTurnError]: Error: DialogContext.beginDialog(): A dialog with an id of 'FollowUpDialog' wasn't found. </b>
this is dialog structure-
dialogs
orderstatus
orderstatus.js
index.js
FollowUp
followUp.js
index.js
i am trying to include FollowUp dialog in OrderStatus Dialog, similary i have other dialogs where i want to begin followup or orderstatus dialog. trying to reuse the dialogs.
One way to do use how we include the file in botjs amd to do adddialog same way i can include in otherfile. But it is redundant work. I am trying to avoid that. Can some one tell me better approach to include the dialog in different dialogs.
code:
Below code is from greeting.js
If you see line where i am doing begindialog.
return await step.beginDialog(ORDER_STATUS_DIALOG);
return await step.beginDialog(ENTITLEMENT_CHECK_DIALOG);
It is error. I am trying to include the dialog which is part of different JS files.
async step => {
if (step.context.activity.channelId == 'directline') {
const buttons = [{
type: ActionTypes.ImBack,
title: 'Repair Order Status',
value: symbolicString.ZEB_GR_STR_013
}, {
type: ActionTypes.ImBack,
title: 'Entitlement Check',
value: symbolicString.ZEB_GR_STR_014
}];
const card = CardFactory.heroCard('', undefined, buttons, {
text: symbolicString.ZEB_GR_STR_015
});
const reply = {type: ActivityTypes.Message};
reply.attachments = [card];
return await step.context.sendActivity(reply);
} else {
return await step.prompt(MENU_PROMPT, symbolicString.ZEB_GR_STR_028);
}
},
async step => {
if (step.context.activity.channelId != 'directline'){
console.log("step greeting dialog next step");
console.log(step);
console.log(step.context.activity);
if (step.context.activity.text == '1'){
return await step.beginDialog(ORDER_STATUS_DIALOG);
}else if (step.context.activity.text == '2'){
return await step.beginDialog(ENTITLEMENT_CHECK_DIALOG);
}
}
return await step.endDialog();
}
]));
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;
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
}
});