I have a suitelet which is creating an array called POdata- this is logging correctly on the suitelet. I want to pass the array to a scheduled script and then perform additional functions. I #think# I am doing this correctly based upon other similar questions - but the log data for the scheduled script is blank.
Here is the Suitelet:
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/ui/serverWidget', 'N/search','N/runtime', 'N/task'],
function(serverWidget, search, runtime, task) {
function getPurchaseOrders() {
var purchaseOrders = search.create({
type: "purchaseorder",
filters:
[
["type","anyof","PurchOrd"],
"AND",
["createdfrom.type","anyof","SalesOrd"],
"AND",
["trandate","within","01/30/2023"],
"AND",
["mainline","is","T"]
],
columns:
[
"trandate",
"entity",
"createdfrom"
]
});
return purchaseOrders;
}
function onRequest(context) {
var request = context.request;
var response = context.response;
if (context.request.method === 'GET') {
var form = serverWidget.createForm({ title: 'Drop Ship Purchase Orders' });
form.addSubmitButton({ label: 'Submit!' });
var sublist = form.addSublist({
id: 'custpage_purchase_orders',
type: serverWidget.SublistType.LIST,
label: 'Drop Ship Purchase Orders'
});
// Show a 'Mark All' button
sublist.addMarkAllButtons();
// Add a checkbox to mark which records should be processed
var printField = sublist.addField({
id: 'custpage_rec_process',
label: 'Process',
type: serverWidget.FieldType.CHECKBOX
});
// Add an internalid to track the line item
var idField = sublist.addField({
id: 'custpage_rec_id',
label: 'Internal ID',
type: serverWidget.FieldType.TEXT
});
sublist.addField({
id: 'custpage_trandate',
label: 'Date',
type: serverWidget.FieldType.DATE
})
sublist.addField({
id: 'custpage_name',
label: 'Vendor Name',
type: serverWidget.FieldType.TEXT
})
sublist.addField({
id: 'custpage_salesorder',
label: 'Sales Order',
type: serverWidget.FieldType.TEXT
})
var purchaseOrders = getPurchaseOrders(); // <—— HERE
var counter = 0;
purchaseOrders.run().each(function(result) {
log.debug("result", result);
var poDate = result.getValue('trandate');
var vendorName = result.getText('entity');
var sOrder = result.getValue('createdfrom');
sublist.setSublistValue({
id: 'custpage_trandate',
line: counter,
value: poDate
});
sublist.setSublistValue({
id: 'custpage_name',
line: counter,
value: vendorName
});
sublist.setSublistValue({
id: 'custpage_salesorder',
line: counter,
value: sOrder
});
counter++;
return true;
})
context.response.writePage(form);
} else if (request.method === 'POST') {
var POdata = [];
var lineCount = request.getLineCount('custpage_purchase_orders');
for (var i = 0; i < lineCount; i++) {
var Vendor = request.getSublistValue({
group: 'custpage_purchase_orders',
name: 'custpage_name',
line: i
}); // "F"
var process = request.getSublistValue({
group: 'custpage_purchase_orders',
name: 'custpage_rec_process',
line: i
});
var soID = request.getSublistValue({
group: 'custpage_purchase_orders',
name: 'custpage_salesorder',
line: i
}); // "value 1"
POdata.push({
'Vendor : Vendor,
'Process?' : process,
'SO Internal ID' : soID
});
}
log.debug('data', POdata);
var scriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: 'customscriptatempschedule',
deploymentId: 'customdeployatempschedule',
params: {
custscript_PO_data: JSON.stringify(POdata)
}
});
var scriptTaskId = scriptTask.submit();
log.debug('scriptTaskId', scriptTaskId);
}
}
}
return {
onRequest: onRequest
};
});
Here is the Scheduled Script:
/**
*
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define(['N/runtime', 'N/record', 'N/search', 'N/config', 'N/ui/serverWidget', 'N/redirect', 'N/url'],
function(runtime, record, search, config, serverWidget, redirect, url) {
function execute(context) {
try{
var getParameter = runtime.getCurrentScript().getParameter({name: 'custscript_PO_data'});
log.debug('getParameter', getParameter);
}
catch(error)
{log.debug('error',error);}
}
return{execute:execute}
});
Thanks in advance!!!
A couple of things:
custscript_po_data