I am just a fresh beginner so forgive me for any silly mistake.
I have two codes, one for the client script page init and the other is for suitlet script. What I am trying to do is a form and a sublist on a suitelet script, then pass exisiting record fields to the sublist form using a client script getValue function.
Is this possible? and how?
Here is my main code: (payrollf is a saved search function for the sublist)
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/log', 'N/record','N/search', 'N/ui/serverWidget'],
/**
* @param {log} log
* @param {search} search
* @param {serverWidget} serverWidget
* @param {record} record
*/
function(log, record, search, serverWidget) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request - Encapsulation of the incoming request
* @param {ServerResponse} context.response - Encapsulation of the Suitelet response
* @Since 2015.2
*/
function onRequest(context) {
var request=context.request;
var response=context.response;
var form=serverWidget.createForm({
title:'Payroll Initiation'
});
var sublist = form.addSublist({
id: 'custpage_payrollsublist',
type: serverWidget.SublistType.LIST,
label: 'Payroll Sublist'
});
var payrollf=payroll();
sublist.addField({
id: 'custpage_amnt',
label: 'Amount',
type: serverWidget.FieldType.TEXT
})
sublist.addField({
id: 'custpage_date1',
label: 'Effective From',
type: serverWidget.FieldType.DATE
})
sublist.addField({
id: 'custpage_rate',
label: 'Rate',
type: serverWidget.FieldType.TEXT
})
sublist.addField({
id: 'custpage_date2',
label: 'Effective Through',
type: serverWidget.FieldType.DATE
})
var path= form.clientScriptModulePath='SuiteScripts/ClientSuitlet.js';
payrollf.run().each(function(){
var counter=0;
sublist.setSublistValue({
id: 'custpage_amnt',
line: counter,
value: path.Amount,
});
sublist.setSublistValue({
id: 'custpage_rate',
line: counter,
value: Rate,
});
sublist.setSublistValue({
id: 'custpage_date1',
line: counter,
value: date1,
});
sublist.setSublistValue({
id: 'custpage_date2',
line: counter,
value: date2,
});
counter++;
return true;
});
response.writePage(form);
}
Client Script code on page initialization:
function pageInit(context) {
var currRecord=context.currentRecord;
var Amount=currRecord.getValue('amnt');
var Rate=currRecord.getValue('rate');
var date1=currRecord.getValue('date1');
var date2=currRecord.getValue('date2');
}
You can pass data from client to sublist by calling the suitelet for example:
var subsidiaryId = rec.getValue('fieldId'); //Read data from suitelet
var suiteUrl = url.resolveScript({
scriptId: 'customscript_xxxxxxx',
deploymentId: 'customdeploy_xxxxxxxx',
// set the script Id and the deployment Id for the suitelet you want to pass the value to.
params : {
custscript_xxxxxx_subsidiary : subsidiaryId, //define a parameter and pass the value to it
}
});
window.location.href = suiteUrl; // replace current window OR
window.open(suiteUrl,"socialPopupWindow","location=no,width=900,height=900,scrollbars=yes,top=100,left=400,resizable = no");//open it a a new window
In your Suitelet you can read the passed parameters.
var sub = request.parameters.custscript_xxxxxx_subsidiary;