0
votes

I'm trying to create a simple afterSubmit user event script that instantly creates an item fulfillment record and cash sale for only gift certificates items on a Sales Order. However, I keep running into an issue on the item fulfillment part where the other items are displayed but not the gift certs. For example I'll have 4 items, two of them gift certificates. Only two items will show on the Item Fulfillment. Both not the Gift Cards.

Also the cash sale transform doesn't allow me to remove line items. I have even tried opening up the newly created cash sale directly after it's creation but no luck.

Any ideas?

function main(type){
    if (type == 'create'){
        //transform for cashsale
        var soId = nlapiGetRecordId();
        var csRec = nlapiTransformRecord('salesorder', soId, 'cashsale');
        var lcount = csRec.getLineItemCount('item');
        for (var i = 1; i <= lcount; i++){
            csRec.selectLineItem('item', i);
            var itemType = csRec.getCurrentLineItemValue('item', 'itemtype', i);
            if (itemType != 'GiftCert') {
                csRec.removeLineItem('item', i);
            }
        }
        nlapiSubmitRecord(csRec);

        //transform for item fulfillment
        var ifRec = nlapiTransformRecord('salesorder', soId, 'itemfulfillment');
        var lcounttwo = ifRec.getLineItemCount('item');

        for (var i = 1; i <= lcounttwo; i++){
            ifRec.selectLineItem('item', i);
            var ifType = ifRec.getCurrentLineItemValue('item', 'itemtype', i);
            if (ifType != 'GiftCert') {
                ifRec.removeLineItem('item', i);
            }
        }
        nlapiSubmitRecord(ifRec);
    }
}
1

1 Answers

1
votes

Depending on how your gift cert is set up the likely issue is that the gift cert is set up so that it may not be fulfilled/received.

If you go to the sales order and create the cash sale you should see the gift cert there and if you do then your script should just bill the gift cert rather than trying to fulfill it