Create Item Fulfillments for multiple locations

 const createIFrecord = (newRecord) => {

            try {

 let locationArray = [];

                //  locationArray.push(bodyLocation);

                let itemLineCount = newRecord.getLineCount({ sublistId: ‘item’ });

                for (let i = 0; i < itemLineCount; i++) {

                    let location = newRecord.getSublistValue({

                        sublistId: ‘item’,

                        fieldId: ‘location’,

                        line: i

                    });

                    if (!locationArray.includes(location)) {

                        locationArray.push(location)

                    }

                }

                log.debug(“location array,”, locationArray)

                for (let j = 0; j < locationArray.length; j++) {

                    let IFRecordObj = record.transform({

                        fromType: record.Type.SALES_ORDER,

                        fromId: newRecord.id,

                        toType: record.Type.ITEM_FULFILLMENT,

                        isDynamic: true

                    });

                    log.debug(“transform obj”, IFRecordObj);

                    let lineCount = IFRecordObj.getLineCount({ sublistId: ‘item’ });

                    log.debug(“line count”, lineCount);

                    for (let i = 0; i < lineCount; i++) {

                        IFRecordObj.selectLine({ sublistId: ‘item’, line: i })

                        let location = IFRecordObj.getCurrentSublistValue({

                            sublistId: ‘item’,

                            fieldId: ‘location’,

                            //line: i

                        });

                        if (location == locationArray[j]) {

                            log.debug(“enter*******”, location)

                            IFRecordObj.setCurrentSublistValue({

                                sublistId: ‘item’,

                                fieldId: ‘itemreceive’,

                                value: true,

                                //line: i

                            });

                        }

                        else {

                            IFRecordObj.setCurrentSublistValue({

                                sublistId: ‘item’,

                                fieldId: ‘itemreceive’,

                                value: false,

                                // line: i

                            });

                        }

                    }

                    let recordId = IFRecordObj.save({

                        enableSourcing: true,

                        ignoreMandatoryFields: true

                    });

                    log.debug(“recordid”, recordId)

                }

            }

            catch (e) {

                log.error(“error@createIFrecord”, e);

            }

        }

        /**

Leave a comment

Your email address will not be published. Required fields are marked *