7px
11/23/2021, 7:30 AMpageInit
fires without issues (alert()
triggers fine), but setting the default value of said field using Field.defaultValue
doesn't seem to work using currentRecord.getField().defaultValue()
, nor does it work being set via the SL script the field was made.battk
11/23/2021, 7:34 AMbattk
11/23/2021, 7:35 AM7px
11/23/2021, 7:53 AMForm.clientScriptModulePath
.
To add, I configured the specified dropdown field to be pre-populated through a saved search. I'm not sure if that's interfering with setting its default value, nor am I even sure if I'm setting it right. As I recall, serverWidget.FieldType.SELECT
selections are a key-value pair, which makes me concerned if I'm setting the values correctly.
Thanks for responding regardless.battk
11/23/2021, 7:55 AM7px
11/23/2021, 8:04 AMfunction onRequest(context) {
if (context.request.method === 'GET') {
var form = serverWidget.createForm({
title: 'Generate Statement'
});
form.clientScriptModulePath = "SuiteScripts/CRM_GenerateStatementPDF/sl_cs_statementpdf.js";
//omitting irrelevant fields
var customerfield = form.addField({
id: 'custpage_customerlabel',
type: serverWidget.FieldType.SELECT,
label: 'Customer',
container: "tab_email"
});
var customerSearch = search.load({
id:"customsearch718"
}).run().getRange({
start: 0,
end: 1000
});
for (var i = 0; i < customerSearch.length; i++) {
var customerName = customerSearch[i].getValue({
name: "entityid"
});
var customerId = customerSearch[i].getValue({
name: "internalid"
});
var newOp = customerfield.addSelectOption({
text: customerName,
value: customerId
});
}
}
for the CS that gets loaded after the form
function pageInit(context) {
var currentRecord = context.currentRecord;
currentRecord.setValue({
fieldId: "custpage_customerlabel",
value: "test"
});
edit: i forgot to include the block of code for the saved searchbattk
11/23/2021, 8:10 AMbattk
11/23/2021, 8:11 AM7px
11/23/2021, 8:14 AMtext
and value
property, correct?battk
11/23/2021, 8:22 AMbattk
11/23/2021, 8:23 AMbattk
11/23/2021, 8:24 AMNElliott
11/23/2021, 8:48 AM7px
11/23/2021, 8:52 AMsetValue
won't work for the dropdown field, but setText
with the matching text
value from the pre-populated entries not only filled in the field, but also matched it to that entry.
That's a long headache cleared. Many thanks again.
@NElliott I went to try out what you said, and much to my surprise it actually worked. I'm not sure why I never thought of using the internal id to set the default value (I just processed the dropdown field as a text-only) field. It also seems to be much faster than the found solution, so thank you very much for this as well. I'll be keeping the found solution for another problem I'm working on then.