How can I trigger the 2nd pass on a dependent line item?

Question

I have an LPG with some user editable fields. When these fields are overridden, the whole line is recalculated automatically. But I want to recalculate also another line which depends on this newly edited value. Is this possible? I used api.markItemDirty("sku") but it doesn't seem to trigger the 2nd pass on the dependent line item.

Answer

This is possible but be aware of the following behavior:

If you mark other SKUs as dirty, they will be processed in a background job, not immediately. (This is because you can theoretically mark many other SKUs as dirty or run multiple loops. So the effect has some delay until it is visible.)

Only if the 2nd pass (and no 3rd or further pass) is required on only the original SKU, then it is calculated immediately.

If multiple items or a single or more other items are marked as dirty, they are processed by a background job.

Found an issue in documentation? Write to us.