When adding a sublist column, through code, is the...
# suitescript
s
When adding a sublist column, through code, is there a way to insert it in front of another column?
e
define the sublist columns in the order you want them to display on the UI
s
Unfortunately/fortunately It's an already existing sublist and not a new sublist or I could
a
Yes there is...
The way you add a column is the same way you do for a Suitelet, assuming you are doing this beforeLoad you would do: Form.addField(options) There is another method: Form.insertField(options)
where form in this context is the Sublist that you get with: Form.getSublist(options)
Then you should be able to do what you need with: • const oSublist = scriptContext.form.getSublist(options) • oSublist.insertField(options)
s
@alien4u sadly, insertSublist is not an option with a sublist 😕
a
insertField
s
sorry, I meant there is no insertField for sublist
a
Yes, there is, the same insertField work for sublist you first need to get the sublist with getSublist and did exactly that few days ago
I did***
s
Copy code
sublist = form.getSublist('item')
field = 'my field stuff'
sublist.insertField
This results in a "insertField is not a valid function"
a
You doing that beforeLoad?
s
Yuppers!
message has been deleted
a
I have that code working….
Please notice getSublist({id:’item’}) if I remember correctly, no sublistId
s
Here is the full code
Copy code
function createField(ctx, lbl) {
    const sublist = ctx.form.getSublist({ id: 'item' });
    const field = sublist.addField({
        id: 'custpage_reason_code',
        type: 'SELECT',
        label: 'testtttt'
        // label: lbl
    });
    field.addSelectOption({
        text: '',
        value: ''
    });

    sublist.insertField({
        field,
        nextfield: 'class'
    });
    return field;
}
a
You only need insertField
No add field needed…
Just insertField without addField
s
It still says insertField is not a function 😕
a
Once Im at my desk I would paste my working code…
s
That'd be awesome. Thanks!
👍 1