Or get the length of a sublist
# suitescript
c
Or get the length of a sublist
c
can i use this for serverwidet.form sublist=
?
message has been deleted
..
Okay.. so it seems like it is impossible to manipulate a widgetform sublist great
r
yeah idk about that
c
so what do i do
why do they make a list
with no methods, so you cant check the length, you cant delete.. you cant do anything
only append
is it atleast a possibility to iterate through it???
and then scrape the values, and then append them to a normal array so i can do what i want with the values
well when i cant get the length i can iterate through it
r
are you trying to get values in POST?
c
i am adding features to a script another employee made. He used a sublist where items are listed with an item id and a quantity. I am trying to make a another "view" where you can see the total quantity for each item: Because on the sublist the same item can appear multiple times
r
you get the values in POST if not wrong and use it
c
so the only way is the get al the values from the POST method
and then start from scratch
r
Form.getSublist(options) you can try this for your particular use case if
c
Holy its annoying
i want to add things to a sublist
but i want do it by logic, so that if the search finds an item the sublist already contains, it should not be appendned
but this is impossible with the sublist widgetform
WHYYY
b
your options for the sublist object are found in the Sublist Object Members
c
Yes
message has been deleted
i can see
But thats answers my questions i guess, no it is not possible
Only way, is instead of checking whether a value is in the sublist, i must append the element to an array everytime an element is added to the sublist
because i cant search the sublist for values,
this way i can know whats in my sublist if i search my array
But there is problems with that aswell
b
although i dont see why you just can't use getSublistValue, the ideal way is to make a list of elements in your sublist
rather than checking it multiple times
c
Because... i want to append to a new sublist
so i can get the values and append them to the new sublist yes
but i only want to append them ONCE
so i need to check the sublist if it contains the object i want to append
b
which should consist of using getSublistValue
on every line
preferably only once
c
okay ill try that
It does not work
on the type of sublist i use
i use
serverwidget.form
b
this sounds like you dont know how forms work
c
maybe
b
usually you add a sublist to a form
and then manipulate how you wish
c
yes you are right
b
in the unusual case you dont add the sublist yourself, you can still get it from the form
c
so if i want to iterate though the sublist
i need to get the length of the sublist
no functioon for that
b
go back to the sublist members and see if one of the 13 members has what you are looking for
c
??
I need to iterate though the sublist to see its members
but to do that i need a foor loop
and to do that i need to have the length of the sublist
b
Sublist Object Members
c
link does not work buddy
b
c
thanks man
b
same as the old one
c
message has been deleted
Yes u see i need to specifi what line
i want it to check ALL lines
but how do i know how many lines there is?
when i cant check the length
b
your options for sublists created by the serverWidget module is limited to what is exposed on a Sublist Object
go though the documentation for the object member to see what your options are
if what you are looking for isnt there, you probably want to start looking at different options
s
one of the 13 members is lineCount, aka if you have the sublistObject, you can do sublistObject.lineCount
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define(['N/ui/serverWidget'], (serverWidget) => {
    const onRequest = (scriptContext) => {
        if (scriptContext.request.method === 'GET') {
            let form = serverWidget.createForm({
                title: 'Simple Form'
            });

            let sublist = form.addSublist({
                id: 'sublist',
                type: serverWidget.SublistType.INLINEEDITOR,
                label: 'Inline Editor Sublist'
            });
//add fields
            sublist.addField({
                id: 'sublist1',
                type: serverWidget.FieldType.DATE,
                label: 'Date'
            });
            sublist.addField({
                id: 'sublist2',
                type: serverWidget.FieldType.TEXT,
                label: 'Text'
            });
//lineCount after you set some values etc..

            var lineCount = sublist.lineCount;
    }
  }

    return {onRequest}
});
i'm guessing, something like this
c
THanks
🙂
r
hey did your problem solve?