Monday 29 June 2015

Adding Incramenting line numbers to a document

I've not had to do much  with our BIP documents recently hense the lack of posts but I got hit with quite a nasty gotcha this morning that I thought I would share.  we have a purchase order document  that is designed to run on JDE data using document number as its primary key.  unfortunately one of our plants (theres always one ) decided that they wanted to run there purchase orders over a range of date criteria instead. and produce one consolidated purchase order.   the problem this produced is the line numbers  all went out of whack as each purchase order appeared separately. so for example if they were trying to consolidate 3 purchase orders one that had 2 lines and one with 3, my line numbers would suddenly change to 1,2,1,2,3  and not 1,2,3,4,5 . grrrrrrrrrrr . I didn't want to have to re write my templates or my jde report so I found the solution with a bit of  googling

first up I set up a variable to hold my ine number at the very top of my document using
<?xdoxslt:set_variable($_XDOCTX, 'COUNTER', 1)?>

luckily im using a for each loop to cycle round my detail lines  so I replaced the field I was using to display line number from the xml  with
<?xdoxslt:get_variable($_XDOCTX, 'COUNTER')?>

and lastly just before the end on my for each loop I incremented my counter using
<?xdoxslt:set_variable($_XDOCTX, 'COUNTER', xdoxslt:get_variable($_XDOCTX, 'COUNTER') + 1)?>


job done :)


No comments:

Post a Comment