Parameter Value is blank passed from Suitelet to Schedule Script

Hello –

I am running a Suitelet and trying to pass an array into a scheduled search to then perform additional functions to that array.   I followed another answer on this site  –

I am getting data from the log.debug(‘data’, POdata) – line in the Suitelet – but the data is not logging on the scheduled search.  I get blank for data.

Suitelet script

/**

* @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 Search 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}

});

Rookie Asked on May 1, 2023 in SuiteScript.
Add Comment
3 Answer(s)
Best answer

Hi,

Did you create the parameter on the script record?

Also, you can’t have uppercase characters in parameter IDs so that’s something to look at too.

Thanks,

Chris

Intermediate Answered on May 3, 2023.
Add Comment

ugh.. thanks Chris – i was hoping it was the uppercase.    But same result when I changed to lowercase.  I do have the parameter declared as free-form text.    I think it is something super easy I am just missing.   Any other thoughts.   Parameter is declared on the Suitelet.   Marked as “store value”.   I tried declaring as long text – that didn’t work either…

Rookie Answered on May 3, 2023.
Add Comment

okay – i figured out my error –

  1.  I had to define the parameter on the scheduled script not the suitelet
  2.  for some reason it did not like JSON.stringify in the params line in the suitelet –  I changed that section to:
     
         var moredata = JSON.stringify(POdata);
         
         var scriptTask = task.create({
           taskType: task.TaskType.SCHEDULED_SCRIPT,
           scriptId: 'customscriptatempschedule',
           deploymentId: 'customdeployatempschedule',
           params: {custscript_po_data: moredata}
         });

Thanks for assistance!!
Rookie Answered on May 3, 2023.

Glad you’ve got it sorted!

on May 4, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor