Hey peeps! This is a bit complex I'm trying to mak...
# suitescript
l
Hey peeps! This is a bit complex I'm trying to make a typeahead/autocomplete field in a suitelet form sublist. Can anyone here explain why I get a "Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load '... Blah" when executing a "getSublistField" within the context of a ClientScript > fieldChanged function?
The form type is
serverWidget.SublistType.INLINEEDITOR
b
share the code, and probably the url its sending to
l
context.currentRecord.getCurrentSublistText({...context})
returns the text of the current field
🤔
context.currentRecord.getField({...context})
returns
null
b
cant really tell with what you are sharing
share enough to reproduce the problem
l
It's just a lot of code to spam the channel with.
b
this is a thread spam all you want
l
LOL 🙂
Copy code
// ClientScript
/**
 * *@NApiVersion 2.0
 * *@NScriptType ClientScript
 * *@NModuleScope public
 */

define(['N/currentRecord'], function (currentRecord) { 'use strict';

    var currentRecordGet = currentRecord.get();
    var lineInit = function (context) {
        console.log('lineInit context', context);
    };
    var fieldChanged = function (context) {
        var getFieldValueByContext = function (_a) {
            var currentRecord = _a.currentRecord, sublistId = _a.sublistId, fieldId = _a.fieldId;
            return currentRecord
                .getCurrentSublistValue({
                sublistId: sublistId,
                fieldId: fieldId
            });
        };
        if (['displayname', 'autocomplete_parent'].includes(context.fieldId)) {
            var displayname = getFieldValueByContext(context);
            console.log('displayname', displayname);
        }
    };
    var sublistChanged = function (context) {
        console.log('sublistChanged context.currentRecord', context);
    };
    var pageInit = function (context) {
        console.log('pageInit context.currentRecord', context);
    };
    var validateLine = function (context) {
        console.log('validateLine context', context);
        return true;
    };
    var validateField = function (context) {
        console.log('validateField context', context);
        return true;
    };
    var batchItemCreate_api = {
        pageInit: pageInit,
        lineInit: lineInit,
        validateLine: validateLine,
        validateField: validateField,
        sublistChanged: sublistChanged,
        fieldChanged: fieldChanged
    };

    return batchItemCreate_api;

});
b
and the suitelet
l
it's ~14k
b
in particular i want to see what the fields look like
l
I'll just pull out that bit.
Copy code
/// Suitelet fields
formFields
        .sort(({ sort: a }, { sort: b }) => a < b ? 0 : 1)
        .forEach(({
          nsid,
          label,
          type,
          source,
          sourceArray,
          isTextField,
          autocomplete
        }) => {
          if (isTextField && !sourceArray) {
            itemList.addField({
              label,
              id: nsid,
              type,
              ...(source && { source })
            })
          } else if (!isTextField && source || sourceArray) {
            const customSelectItem = itemList.addField({
              label,
              id: nsid,
              type: serverWidget.FieldType.SELECT
            })
            // Add blank
            customSelectItem.addSelectOption({ value: '', text: '' })
            if (sourceArray) {
              sourceArray.forEach(({ value, text }) => {
                customSelectItem.addSelectOption({ value: String(value), text: String(text) })
              })
            } else if (autocomplete) {
              customSelectItem.updateDisplayType({
                displayType: serverWidget.FieldDisplayType.HIDDEN
              })
              itemList.addField({
                label: `_${label}_`,
                id: `autocomplete_${nsid}`,
                type: serverWidget.FieldType.TEXT
              })
              // add the custom typeahead search
            } else {
              getSelectOptions(source).forEach(({ value, text }) => {
                customSelectItem.addSelectOption({ value: String(value), text: String(text) })
              })
            }

            // noop
          }
        })
b
what value is in formFields
l
really I just want to be able to add
SELECT
items to fields based off the contents of a sibling fields
b
add logging to see what incoming gets look like
l
formFields = Array<AddFieldOptions>
b
select fields do a get to the suitelet to get their little popup
l
add logging to the client script or to the Suitelet?
b
to your suitelet
l
ahh
b
your suitelet needs to respond to the get with a form that has the requested field on it
l
Lemme see
b
usually the same form most of the time
l
just
log.debug(JSON.stringify(context.request))?
b
probably want to use the second details perameter
it mas more characters
l
getSublistValue?
What am I looking for?
b
to see if your suitelet receives a get triggered from your fieldChanged function
l
ahh
So I can just do a
log.debug(JSON.stringify(context.request.body))
and watch the execution log.
b
you dont really want the body of a GET
l
That may be something handled on POST
b
just log request
l
I'll go do some digging and get back in ~ an hour.
Thanks!
b
if im gone by them, keep in mind my explanation about gets to your suitelet, and what you have to do to fix it