Search code examples
netsuitesuitescript2.0

How to source just parent items in a select field on suitelet form (API 2.0)?


i am creating a suitelet form that will generate a pdf in POST. I need a field in my suitelet form, in which list of parent items can be selected(e.g. 1001 not 1001: 210-XL)for filtering purposes and all the items (child items) related to it can be printed in the PDF. Can anyone tell me what should i do?


Solution

  • It is not possible to add only Parent items in SELECT field on Suitelet. You will need to add SELECT Field and then addSelectOption.

    var select = form.addField({
        id: 'selectfield',
        type: serverWidget.FieldType.SELECT,
        label: 'Select'
    });
    
    var itemSearchObj = search.create({
        type: "item",
        filters:
            [
                ["parent.isinactive", "is", "F"],
                "AND",
                ["formulatext: {parent}", "isnotempty", ""]
            ],
        columns:
            [
                search.createColumn({
                    name: "parent",
                    summary: "GROUP",
                    label: "Parent"
                }),
                search.createColumn({
                    name: "internalid",
                    join: "parent",
                    summary: "GROUP",
                    label: "Internal ID"
                })
            ]
    });
    
    itemSearchObj.run().each(function (result) {
        select.addSelectOption({
            value: result.getValue({
                name: "parent",
                summary: "GROUP",
                label: "Parent"
            }),
            text: result.getValue({
                name: "internalid",
                join: "parent",
                summary: "GROUP"
            })
        });
    
        return true;
    });
    

    I hope, this will help.