Line Items

Hi,


I have a system whereby when a quote is created there is an automatic line item added which is a delivery charge applied to all quotes and orders. Each customer record has a delivery charge on their company record from where the value is pulled for this. This is fine.

I have an issue where the customer would like this to appear as the last line item in the quote. On the quote entity there is a line number which I have exposed for them so they can reorder the line items as they wish but sometimes they forget to move the delivery charge to the last position. So, I need to have a script on the insert or postinsert record of lineitems that reorders them so that the delviery charge line item is always 1 more than the highest order line item in the list. Initially I had thought of creating the delivery charge line item as item number 100 and I'd hoped that as more line items were added they would start at 1 and move higher but no, they just take max line item number + 1 so any line items after the delivery charge starts at 101.


I know this is a script but I just cannot get it right. Obviously I'll be updating all quote items and I'll need to use SaveChangesNoTLS() as a function to prevent the firing of the other tablescripts on the quote.


Any help welcomed!

Lee

  • 0

    Hi Lee,

    Here is what you can do.

    Add an integer field named “Deliverychargeitem“ at quote item level

    1. When you are creating delivery charge line item automatically set this field to 1
    2. On update record function of quote items get the max line number for quote items belonging to current quote. Now at the time of getting this max value skip the item where “Deliverychargeitem” is set to 1 i.e. ignore delivery charge line item.
    3. Add + 1 to value collected in step 3 and update this value in line number of line item where the “Deliverychargeitem“ is set to 1. Pass quote id in where clause. This will ensure that the correct line item is updated always with correct value

    Hope this helps!

    Regards,

    Dinesh