How to Set Logic Based Product Input Filter

If you need to add a product picker with a pre-filtered product (based on e.g., Sales Organization) somewhere where the product is not a default part of the context (e.g., documents in Agreements & Promotions), you can use the Product Input Filter logic. The overall idea is very similar to the approach used for filtering the customer input described in How to Set Logic Based Customer Input Filter for Quotes. Just select "Product Input Filter" as Nature of the logic (instead of "Customer Input Filter"). You will then call it like this:

But doing per lines is a bit tricky. This api.product call will always create an input for you, meaning that after every recalculation the input selected by the user will "disappear". But creating this input just once might not be as easy as it looks. The following snippet shows one way to do it: