How to filter custom selection field in sublist

Hi,
Good Day!
Is it possible to filter the custom selection field in sublist based on the item using suitescript (userevent and clientscript). Below my snipped code but unfortunately the result was still have a value in every item line of custom selection field column and only display the last item of substitute item.
User Event Script
var form = scriptContext.form;
var sublistItem = form.getSublist({ id: ‘item’ })
var newColumn = sublistItem.addField({
    id: ‘custpage_item_substitute_wo_line’,
    type: ‘select’,
    label: ‘Custom Item substitute’
});

Client Script
function alterFunct(scriptContext) {
    const currentRecord = scriptContext.currentRecord;
    bomType = currentRecord.getText({ fieldId: ‘assemblyitem’ });
    console.log(‘bomType’, bomType);
    const countLinesInit = currentRecord.getLineCount({ sublistId: ‘item’ });
    console.log(‘countLinesInit’, countLinesInit);
    var filterSubsItemInit = searchAlternativeItems(bomType);
    var subsituteSKUFIeld;
    setTimeout(function () {
        for (var j = 0; j < countLinesInit; j++) {
            currentRecord.selectLine({
                sublistId: ‘item’,
                line: j
            });
            var item_name = currentRecord.getSublistText({ sublistId: ‘item’, fieldId: ‘item’, line: j });
            subsituteSKUFIeld = currentRecord.getSublistField({
                sublistId: ‘item’,
                fieldId: ‘custpage_item_substitute_wo_line’,
                line: j
            });
            subsituteSKUFIeld.removeSelectOption({ value: null });
            if (filterSubsItemInit.length != 0) {
                for (var x = 0; x < filterSubsItemInit.length; x++) {
                    if (x == 0)
                        subsituteSKUFIeld.insertSelectOption({
                            value: “”,
                            text: “”,
                        });
                    if (filterSubsItemInit[x].orig === item_name) {
                        var id = filterSubsItemInit[x].id;
                        var name = filterSubsItemInit[x].alter;
                        subsituteSKUFIeld.insertSelectOption({
                            value: id,
                            text: name
                        });
                    }
                }
            }
        }
    }, 500);
}
function searchAlternativeItems(bom_name) {
    var customrecord456SearchObj = search.create({
        type: “customrecord456”,
        filters: [
            [“isinactive”, “is”, “F”], “AND”, [“custrecord_ii_bom_item.name”, “is”, bom_name], “AND”,
            [“formulatext: case when {custrecord_alter_comp.custitem_retire_item}=’T’ then ‘Retire’ when {custrecord_alter_comp.custitem_is_eol}=’T’ and {custrecord_alter_comp.locationquantityonhand}=’0′ then ‘End  of Life’ else ‘Active’ end”, “is”, “Active”]
        ],
        columns: [
            search.createColumn({ name: “name”, label: “ID” }),
            search.createColumn({ name: “custrecord_ii_bom_item”, label: “Bill of Materials” }),
            search.createColumn({ name: “custrecord_ii_orig_comp”, label: “Original Component” }),
            search.createColumn({ name: “custrecord_alter_comp”, label: “Alternative Component” }),
            search.createColumn({ name: “internalid”, join: “CUSTRECORD_ALTER_COMP”, label: “Internal ID” })
        ]
    });
    resultObj = []
    customrecord456SearchObj.run().each(function (result) {
        obj = {}
        obj.id = result.getValue({ name: “internalid”, join: “CUSTRECORD_ALTER_COMP” })
        obj.orig = result.getText({ name: “custrecord_ii_orig_comp” })
        obj.alter = result.getText({ name: “custrecord_alter_comp” })
        resultObj.push(obj)
        return true;
    });
    return resultObj;
}

Rookie Asked on July 20, 2022 in SuiteCloud.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor