Search code examples
netsuitesuitescriptsuitescript2.0

Create Item fulfillment for selected items


This is my suitelet 2.0 and I want to create item fulfillment for selected items also shows the error message if the item, quantity, and lot number do not match with the sales order item, quantity, and lot number. else create item fulfillment. Please help! var form = serverWidget.createForm({ title: "Create Item Fulfillment" }); form.addSubmitButton({ label: 'Submit' });

          var soNumber = form.addField({
            id : 'custpage_so_number',
            type : serverWidget.FieldType.TEXT,
            label : 'Sales Order Number'
        });

        var sublist = form.addSublist({
            id: "item_sublist",
            type: serverWidget.SublistType.INLINEEDITOR,
            label: "Item"
          });
          sublist.addField({
            id: "itemname",
            type: serverWidget.FieldType.SELECT,
            label: "Item",
            source: "item"
          });
          sublist.addField({
            id: "lotnumber",
            type: serverWidget.FieldType.TEXT,
            label: "Lot/Heat Number"
          });
          sublist.addField({
            id: "quantity",
            type: serverWidget.FieldType.TEXT,
            label: "Quantity"
          });
    }
    catch(e)
    {
        log.debug("error in get",e);
    }

    context.response.writePage(form);

    }
    else if (context.request.method === 'POST') {

        try{
    log.debug("suitelet is posting")
      
        }catch(er)
        {
            log.debug("error in post method",er);
        }
        
    }
}

});


Solution

  • Your code is very brief and does not demonstrate whether data is loading into the fields you have created in your Suitelet. Working with what you have shared, you will want to add another column that would allow a user to SELECT the item they want to fulfill.

    Example - adding a clickable checkbox in your Suitelet:

        sublist.addField({ id: 'custpage_apply', label: 'Select Item to Fulfill', type: serverWidget.FieldType.CHECKBOX });
    

    Next, you will want to read this new checkbox in your POST statement of the code; whereby you only attempt to fulfil an order when the checkbox is marked TRUE.

    Example:

    ...GET code above....
        else if (context.request.method === 'POST') {
    
        //BEGIN: Create fulfillment object, link to sales/purchase order:
        var objRecord = record.transform({
            fromType: record.Type.SALES_ORDER,
            fromId: {id},
            toType: record.Type.ITEM_FULFILLMENT,
            isDynamic: false,
        });
    
        try{
            //Capture table line count
            var getCount = context.request.getLineCount('item_sublist');
            
            for (var i = 0; i < getCount; i++) {
                var isApply = context.request.getSublistValue({
                    group: 'item_sublist',
                    name: 'custpage_apply',
                    line: i
                });
    
                if (isApply == 'T') {
         
                     //ADD CODE TO TRACK and MARK MATCHING ITEM TO FULFILL
                     
                }
            }
             
            record.save(objRecord);
            context.response.write('FULFILMENT NOW SAVED');
    
      
        }catch(er)
        {
            log.debug("error in post method",er);
            context.response.write('ERROR FOUND ' + er);
    
        }
        
    }