Zoeken…


Invoering

NetSuite-records zijn onderverdeeld in Body-velden en sublijsten. Er zijn vier soorten sublijsten: Statisch, Editor, Inline-editor en Lijst.

We kunnen regelitems toevoegen, invoegen, bewerken en verwijderen met behulp van Sublijst-API's.

Voor een referentie over welke sublijsten SuiteScript ondersteunen, zie de NetSuite Help-pagina getiteld "Scriptable Sublists".

Opmerkingen

Sublijstindices

Elk regelitem in een sublijst heeft een index die we kunnen gebruiken om ernaar te verwijzen.

In SuiteScript 1.0 zijn deze indices gebaseerd op 1 , dus het eerste regelitem heeft index 1 , het tweede heeft index 2 , enzovoort.

In SuiteScript 2.0 zijn deze indices gebaseerd op 0 , dus het eerste regelitem heeft index 0 , het tweede heeft index 1 , enzovoort. Dit komt natuurlijk beter overeen met Array-indexering in de meeste talen, inclusief JavaScript.

Standaard versus dynamische modus

De API die we gebruiken voor interactie met een sublijst is afhankelijk van of we met het record werken in de standaard- of dynamische modus.

Met de API's in de standaardmodus kunnen we eenvoudig de index van de regel waarmee we willen werken als parameter voor de juiste functie opgeven.

De API's in de dynamische modus volgen een patroon:

  1. Selecteer de lijn waarmee we willen werken
  2. Wijzig de geselecteerde regel naar wens
  3. Leg de wijzigingen in de regel vast

Als we in de dynamische modus niet de wijzigingen doorvoeren voor elke regel die we wijzigen, worden deze wijzigingen niet doorgevoerd wanneer de record wordt opgeslagen.

beperkingen

Om te kunnen werken met sublijstgegevens via SuiteScript, moeten we een referentie in het geheugen hebben naar het record. Dit betekent dat het record ofwel uit de scriptcontext moet worden opgehaald, ofwel dat we het record uit de database moeten laden.

We kunnen niet werken met sublijsten via lookup of submitFields- functionaliteit.

Statische sublijsten ondersteunen helemaal geen SuiteScript.

Referenties:

  • NetSuite Help: "Wat is een sublijst?"
  • NetSuite Help: "Sublijsttypen"
  • NetSuite Help: "Scriptbare sublijsten"
  • NetSuite Help: "Werken met sublijstregelitems"
  • NetSuite Help: "Sublijst API's"
  • NetSuite Help: "Werken met records in dynamische modus"

[1.0] Hoeveel regels op een sublijst?

// How many Items does a Sales Order have...

// ... if we're in the context of a Sales Order record
var itemCount = nlapiGetLineItemCount("item");

// ... or if we've loaded the Sales Order
var order = nlapiLoadRecord("salesorder", 123);
var itemCount = order.getLineItemCount("item");

[1.0] Sublijsten in standaardmodus

// Working with Sublists in Standard mode ...

// ... if the record is in context:

// Add item 456 with quantity 10 at the end of the item sublist
var nextIndex = nlapiGetLineItemCount("item") + 1;
nlapiSetLineItemValue("item", "item", nextIndex, 456);
nlapiSetLineItemValue("item", "quantity", nextIndex, 10);

// Inserting item 234 with quantity 3 at the beginning of a sublist
nlapiInsertLineItem("item", 1);
nlapiSetLineItemValue("item", "item", 1, 234);
nlapiSetLineItemValue("item", "quantity", 1, 3);

// Insert item 777 with quantity 2 before the end of the last item
var itemCount = nlapiGetLineItemCount("item");
nlapiInsertLineItem("item", itemCount);
nlapiSetLineItemValue("item", "item", itemCount, 777);
nlapiSetLineItemValue("item", "quantity", itemCount, 2);

// Remove the first line item
nlapiRemoveLineItem("item", 1);

// Remove the last line item
nlapiRemoveLineItem("item", nlapiGetLineItemCount("item"));

// ... or if we have a reference to the record (rec):

// Add item 456 with quantity 10 at the end of the item sublist
var nextIndex = rec.getLineItemCount("item") + 1;
rec.setLineItemValue("item", "item", nextIndex, 456);
rec.setLineItemValue("item", "quantity", nextIndex, 10);

// Insert item 777 with quantity 3 at the beginning of the sublist
rec.insertLineItem("item", 1);
rec.setLineItemValue("item", "item", 1, 777);
rec.setLineItemValue("item", "quantity", 1, 3);

// Remove the first line
rec.removeLineItem("item", 1);

// Remove the last line
rec.removeLineItem("item", rec.getLineItemCount("item"));

[1.0] Sublijsten in dynamische modus

// Adding a line item to the end of a sublist in Dynamic Mode...

// ... if the record is in context:
nlapiSelectNewLineItem("item");
nlapiSetCurrentLineItemValue("item", "item", 456);
nlapiSetCurrentLineItemValue("item", "quantity", 10);
nlapiCommitLineItem("item");

// ... or if we have a reference to the record (rec):
rec.selectNewLineItem("item");
rec.setCurrentLineItemValue("item", "item", 456);
rec.setCurrentLineItemValue("item", "quantity", 10);
rec.commitLineItem("item");

[1.0] Zoek een regelitem

// Which line has item 456 on it...

// ... if we're in the context of a record
var index = nlapiFindLineItemValue("item", "item", 456);
if (index > -1) {
    // we found it...
} else {
    // item 456 is not in the list
}

// ... or if we have a reference to the record (rec)
var index = rec.findLineItemValue("item", "item", 456);
if (index > -1) {
    // we found it on line "index"...
} else {
    // item 456 is not in the list
}

[2.0] Hoeveel regels op een sublijst?

// How many lines in a sublist in SuiteScript 2.0...

require(["N/record"], function (r) {
    var rec = r.load({
        "type": r.Type.SALES_ORDER,
        "id": 123
    });

    // How many lines are on the Items sublist?
    var itemCount = rec.getLineCount({"sublistId": "item"});
});

[2.0] Sublijsten in standaardmodus

// Working with a sublist in Standard Mode in SuiteScript 2.0...

require(["N/record"], function (r) {
    var rec = r.create({
        "type": r.Type.SALES_ORDER,
        "isDynamic": false
    });

    // Set relevant body fields ...

    // Add line item 456 with quantity 10 at the beginning of the Items sublist
    rec.setSublistValue({"sublistId": "item", "fieldId": "item", "value": 456, "line": 0});
    rec.setSublistValue({"sublistId": "item", "fieldId": "quantity", "value": 10, "line": 0});

    // Insert line item 238 with quantity 5 at the beginning of the Items sublist
    rec.insertLine({"sublistId": "item", "line": 0});
    rec.setSublistValue({"sublistId": "item", "fieldId": "item", "value": 238, "line": 0});
    rec.setSublistValue({"sublistId": "item", "fieldId": "quantity", "value": 5, "line": 0});

    // Insert line item 777 with quantity 3 before the last line of the Items sublist
    var lastIndex = rec.getLineCount({"sublistId": "item"}) - 1; // 2.0 sublists have 0-based index
    rec.insertLine({"sublistId": "item", "line": lastIndex}); // The last line will now actually be at lastIndex + 1
    rec.setSublistValue({"sublistId": "item", "fieldId": "item", "value": 777, "line": lastIndex});
    rec.setSublistValue({"sublistId": "item", "fieldId": "quantity", "value": 3, "line": lastIndex});

    // Remove the first line
    rec.removeLine({"sublistId": "item", "line": 0});

    // Remove the last line
    rec.removeLine({"sublistId": "item", "line": rec.getLineCount({"sublistId": "item"}) - 1});

    rec.save();
});

[2.0] Sublijsten in dynamische modus

// Working with Sublists in Dynamic Mode in SuiteScript 2.0...

require(["N/record"], function (r) {
    var rec = r.create({
        "type": r.Type.SALES_ORDER,
        "isDynamic": true
    });

    // Set relevant body fields ...

    // Add line item 456 with quantity 10 at the end of the Items sublist
    var itemCount = rec.selectNewLine({"sublistId": "item"});
    rec.setCurrentSublistValue({"sublistId": "item", "fieldId": "item", "value": 456});
    rec.setCurrentSublistValue({"sublistId": "item", "fieldId": "quantity", "value": 10});
    rec.commitLine({"sublistId": "item"});

    // Insert line item 378 with quantity 2 at the beginning of the Items sublist
    rec.insertLine({"sublistId": "item", "line": 0});
    rec.selectLine({"sublistId": "item", "line": 0});
    rec.setCurrentSublistValue({"sublistId": "item", "fieldId": "item", "value": 378});
    rec.setCurrentSublistValue({"sublistId": "item", "fieldId": "quantity", "value": 2});
    rec.commitLine({"sublistId": "item"});

    // Insert line item 777 with quantity 3 before the last line of the Items sublist
    var lastIndex = rec.getLineCount({"sublistId": "item"}) - 1; // 2.0 sublists have 0-based index
    rec.insertLine({"sublistId": "item", "line": lastIndex}); // The last line will now actually be at lastIndex + 1
    rec.selectLine({"sublistId": "item", "line": lastIndex});
    rec.setCurrentSublistValue({"sublistId": "item", "fieldId": "item", "value": 777});
    rec.setCurrentSublistValue({"sublistId": "item", "fieldId": "quantity", "value": 3});
    rec.commitLine({"sublistId": "item"});

    // Remove the first line
    rec.removeLine({"sublistId": "item", "line": 0});

    // Remove the last line
    rec.removeLine({"sublistId": "item", "line": rec.getLineCount({"sublistId": "item"}) - 1});

    rec.save();
});

[2.0] Zoek een regelitem

// Finding a specific line item in SuiteScript 2.0...

require(["N/record"], function (r) {
    var rec = r.load({
        "type": r.Type.SALES_ORDER,
        "id": 123
    });

    // Find the line that contains item 777
    var index = rec.findSublistLineWithValue({"sublistId": "item", "fieldId": "item", "value": 777});

    // find returns -1 if the item isn't found
    if (index > -1) {
        // we found it on line "index"
    } else {
        // item 777 is not in the list
    }
});


Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow