Core
Core

Reputation: 37

NetSuite: How can I change current subtab in SO

I added a new Transaction Body Field in SO. And I want to change the current subtab based on the value of the custom select option. I already add a ClientScript. What I want to know is the function that change current subtab.

EntryPoint.fieldChanged = (scriptContext) => {
    const LOGTITLE = "fieldChanged " + scriptContext.currentRecord.id;
    
    try {
        var record = scriptContext.currentRecord;
    
        if (scriptContext.fieldId == 'custpage_paymentoption') {
            var currentOption = record.getValue({
                fieldId: 'custpage_paymentoption',
            })
            log.debug('currentOption', currentOption);

            
        }
    } catch (e) {
        log.error(LOGTITLE, JSON.stringify(e));
    }
};

As you know, in Sales Order Record default subtab is set as Item. I want to change it after I change the value of the custom select option. Please let me know if someone can give me advice.

Upvotes: 0

Views: 379

Answers (3)

Serhii Stepanenko
Serhii Stepanenko

Reputation: 116

I noticed you want to update your subtab in SO. You can achieve this using commitLIne() function. Under is sample code.

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */

define([], function() {
  function pageInit(context) {
    // Switch to the desired subtab
    var sublistId = 'item'; // ID of the sublist containing the subtab
    var subtabIndex = 1; // Index of the subtab you want to switch to (0-based)

    // Select the subtab
    context.currentRecord.selectLineItem({
      sublistId: sublistId,
      line: subtabIndex
    });

    // Commit the changes to switch to the subtab
    context.currentRecord.commitLine({
      sublistId: sublistId
    });
  }

  return {
    pageInit: pageInit
  };
});

Upvotes: 1

Krypton
Krypton

Reputation: 5286

You can use the (undocumented, unsupported) ShowTab() function to switch tabs. Get the internal ID of the tab by inspecting it in the dev tools, and use ShowTab({{tab_internal_id}}, false) to switch to that tab. More information at this SuiteAnswers article.

(The article is about generating a direct URL to a page opened to a specific tab, but it contains information that will help you to use the ShowTab() function also.)

Upvotes: 0

AnthoVdo
AnthoVdo

Reputation: 224

If your goal is to update the form to add a subtab according to the field value, it isn't possible to do it with a client script.
The form is set on the server and not on the client side.
But you can use you client script to reload the page and add informations inside the url.
You will have a user event that will check the url information and update the form according to it.
To update the form, you need to use the server widget module

Upvotes: 0

Related Questions