When an inventory item is added, a discount item n...
# general
m
When an inventory item is added, a discount item needs to be added automatic. Unfortunately my script is overwriting the inventory items always... any idea?
Copy code
context.currentRecord.selectNewLine({sublistId: 'item', line: 1});

                context.currentRecord.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'item',
                    value: 20648,
                    ignoreFieldChange: true,
                    forceSyncSourcing: true
                });

                context.currentRecord.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'amount',
                    value: (discount / 100) * currentAmount,
                    ignoreFieldChange: true,
                    forceSyncSourcing: false
                });

                context.currentRecord.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'taxcode',
                    value: 6,
                    ignoreFieldChange: true,
                    forceSyncSourcing: false
                });

                context.currentRecord.commitLine({
                    sublistId: 'item',
                    ignoreRecalc: true
                });
b
stop ignoring field changes and recalc
force sync sourcing while setting all lines
a
Is it on sales orders and did you try using Item groups? You can add a discount item within the group and can be modified after it is added.
m
@Ashish Atri Its more that discount is based on a matrix Customer and Brand and discount %, we search for it pick it up and calculate the discount amount and add it.
a
Got It!
m
Everytime I add the item I have the customer on the header, brand of the item on line, I go look in my matrix (custom record), find the combination pick up the percentage and calculate amount item * Discount % and add the discount item underneath, the only issue is that the invenotry item gets overwritten by my client script.