Sublist Item No doesn't update when items removed
Hi everyone
I have a SharePoint form for recording expenses, which uses a sublist to hold the individual items for the monthly expenses. The sublist automatically numbers each item and there is also a total expenditure field that holds a sum of all items in the sublist:
This works fine when items are added but if I remove an item from the sublist, the Item No field is out of order:
To automatically calculate the item no I use two lines of code. The first is set to run on form load:
window.lastPositionNumber = [[@SubLists.Monthly_Items.Item_x0020_No.Max]];
The second is used as the calculated expression for the Item No field:
++window.lastPositionNumber
I can see that my code doesn't take into account if an item is deleted from the sublist, but I wondered if this is possible? I'm not sure if there is a way I can test for whether an item has been deleted and then recalculate the item numbers accordingly?
I'd be grateful for any advice anyone could give. Thanks in advance.
-
Hi Gareth,
Inside the calculated Expression you will only increase the number, and actually not search for the Item with the max number. So if you delete a Sublist-Item, this expression ("++window.lastPositionNumber") will be triggered again and increase your number.
Instead, you should be able to use a recalculating Expression [[@SubLists.Monthly_Items.Item_x0020_No.Count]] or [[@SubLists.Monthly_Items.Item_x0020_No.Max]] inside your calculated Expression directly.
Kind regards
Pius
PS:
Unfortunately, I am not able to see the Images. So hopefully i did get your question anyway?
Can you please add them to your post.
0 -
Hi Pius
Thank you for the quick reply and apologies about the pictures not appearing. I've now updated my original post so hopefully the images are visible now.
As you can see from the images the issue is if I delete an item that isn't the last one in the list. I was wondering if there's a way I can then recalculate the item numbers for all remaining items and adjust them? In my example above, after deleting Item 2 I would want the number for Item 3 to automatically change to 2 to fit in with the new order.
0 -
Hi Gareth
Now (with the added images) I understand what you try to reach. Unfortunately, I do not have an easy solution for you. When you delete a subsist item, the only expression that will be trigger, is the one for the item, before the deleted one.
The only thing comes into my mind, would be to write a script to grab the active cell of the current item and then iterate over the table cells below the item and update the values. All by custom jQuery/js scripting. And you must go sure to only trigger this update process if an item was deleted.
So, not an easy task. Sorry for the bad news.
Kind regards
Pius
0
Please sign in to leave a comment.
Comments
3 comments