How to modify a SuiteLet sublist via linked Client Script?

Hi there, I have a SuiteLet with an empty sublist. A button on the SuiteLet directs to a Client Script which is attempting to populate the sublist. I’m encountering a strange error on my Client Script—”undefined is not an object (evaluating ‘olddata[i]’).” This is a JavaScript error, I believe referring to “rec” in the following code. The error initiates on “rec.commitLine.”
function populateSublist(fieldValues, rec, availableItems) {
        log.debug("Rec", rec);
        if (availableItems[0]) {
            for (i = 0; i < availableItems.length; i++) {
                try {
                    rec.selectNewLine({
                        sublistId: 'custpage_items_sublist'
                    });

                    rec.setCurrentSublistValue({
                        sublistId: 'custpage_items_sublist',
                        fieldId: 'custpage_parent_frame',
                        value: availableItems[0].item_parent_frame
                    });

                    // More values being set...

                    rec.commitLine({ // <=== *** RIGHT HERE ***
                        sublistId: 'custpage_items_sublist'
                    });
                } catch (e) {
                    log.error("Unable to commit line - " + e.name, e.message);
                }
            }
        } else {
            log.debug("No available items for given parameters.")
        }

 

Here are some things I know:

  1. “rec” is working previously and getting field names I need.
  2. “rec” is showing “{“id”:””,”type”:null,”isDynamic”:true}” in my execution log.
  3. The beginning of my Client Script uses “var rec = currentRecord.get();” to receive the record.

Is it possible to modify a SuiteLet sublist from a Client Script? I’ve never done this in particular before, so I’m at a loss here. Any help or ideas are immensely appreciated! Thanks!

Rookie Asked on December 18, 2020 in SuiteScript.
Add Comment
3 Answer(s)

Yes it is possible.  Firstly what is the entry point calling your script?  rec should context.currentRecord, not currentRecord.get().  Nothing really looks wrong with select/set/commit in the loop, so it is probably a data problem or a problem with how you are defining rec.

As a reference, this simple client script works fine with adding a line to sublist.

 
exports.fieldChanged = function fieldChanged(context) {
  if (context.fieldId == 'custpage_fieldone') {
    var rec = context.currentRecord;
    rec.selectNewLine({
      sublistId: 'custpage_testsub'
    });
    rec.setCurrentSublistValue({
      sublistId: 'custpage_testsub',
      fieldId: 'custpage_columnone',
      value: rec.getValue('custpage_fieldone')
    });
    rec.commitLine({
      sublistId: 'custpage_testsub'
    });
  }
}
return exports;
Intermediate Answered on December 18, 2020.

Yes, the client script has a pageInit() that is not being used except for a debug. My function, “onLookupItemsButtonClick()” is being called by the SuiteLet button. I realize I might be able to use a lib. script for all this, but that may be something I change down the road.

If I do use “context.currentRecord”, this Client Script won’t run at all when the SuiteLet button is clicked—likely indicating an error.

RE: How to modify a SuiteLet sublist via linked Client Script?

Thanks for your reply and help! Let me know if you have any other thoughts on this.

on December 18, 2020.
Add Comment

Weird sublist behavior means you should use forceSyncSourcing.

Advanced Answered on December 18, 2020.
Add Comment

We were able to resolve this issue today. This problem was due to defining the SuiteLet sublist as SublistType.LIST. NetSuite doesn’t support editing sublists defined as “LIST” outside of server-side scripts. Thus, we encountered this strange error when trying to edit it via the Client Script.

Two possible solutions are:

  1. Change SuiteList SublistType to “INLINEEDITOR.”
  2. Move sublist editing over to Server Side (SuiteLet).

 

Thanks! Perhaps this will help someone out in the future at least.
Rookie Answered on December 18, 2020.

Hi Ben..i am looking for the same issue..can you please share the correct suitelet and client code asap

on December 25, 2020.
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   Limebox   Become a Sponsor   Become a Sponsor