Renerabbitt Posted August 22, 2023 Share Posted August 22, 2023 I am learning macros, at a decent pace, but this consistantly eludes me. I would like to see a WORKING and COMPLETE example of a macro that accumulates totals which includes an individual publisher with a count greater than 1. Example, I want to assign the value of 20 to a custom field on an object, and add it to an accumulating total from other publishers that have values in that same custom field. Then report the count and also the total to global macros so I can use them in other calcs. Everytime I try and make this work, the accumulation compounds for every redraw, despite me putting in a step for resetting the totals. Link to comment Share on other sites More sharing options...
SHCanada2 Posted August 22, 2023 Share Posted August 22, 2023 if you have a unique id for the object (such as a schedule number), the label can add the value to an array which has the unique id. so before adding it to the array, you check to see if it is there first. if it is, you update, if not you add. I think joe uses ObjectId as the unique identifier The only downside is when an item is removed, or if the unique ID changes. I have not found a great solution. One is to reset the whole thing and let it repopulate the array Link to comment Share on other sites More sharing options...
SHCanada2 Posted August 22, 2023 Share Posted August 22, 2023 so something like: ..manage initialization and setting of variables... i = 0 j = $Array1.length lfound = false while i < j if $Array1[i][0] == owner.schedule_number $Array1[i]= [owner.schedule_number,@customfield] lfound = true end i = i+1 end i=$Array1.length if lfound == false $Array1[i] = [owner.schedule_number, @customfield] end The above assumes there are no duplicate objects with the same schedule number Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now