Get ( FoundCount ) returns the found count for the current layout in the current window. As long as your script assigns the value to a global variable while on the layout with the desired found count, the method that you describe should work for you. If I am correct that we have previously discussed this, it does not appear that this function is the source of your trouble. Either your script is not finding the correct set of records or the error lies in another part of your system.
I'd look at how your script finds the records you want to count with this function and the layout that is current at the time you assign this value to a variable.
OK. The script now sets $$SurveyFoundCount before leaving the Survey's layout but when I switch to the Issues layout (Ranking of Issues), the count of Issues is based on all records in Join_Issues_Mentioned instead of only those from PriorityMarkets.
I tried two ways to switch from Surveys to Ranking Report in Join_Issues_Mentioned.
After setting the global variable
1. Script step Go To Layout Ranking Report
2. New Window, Go To Layout Ranking Repor
In both cases, the count for each Issue shown on the Ranking Report was the total for the entire Join_Issues_Mentioned table, not just the count of Issues from Surveys from PriorityMarkets. The good news is that the FoundCount from Surveys was correct. :)
But with a global variable, its value will not change just because you change layouts. Neither will opening a new window change the value. I would check to be sure that the calculations in question actually refer to the global variable and not some other value.
I'd also check for any script triggers tripped by the change in layouts that might perform a script that modifies the value of the variable.
OK. Here's what I'm doing.
Starting with all records found in both Surveys and Join_Issues_Mentioned
- Clear the variable $$SurveyFoundCount
- Go to Survey Layout with fields from both Surveys and Issues_Mentioned
- Enter Find Mode [Restore] Find Surveys from PriorityMarkets AND with anything in Issues in Join_Issues_Mentioned
- Perform Find [Restore] Find Surveys from PriorityMarkets AND with anything in Issues in Join_Issues_Mentioned
- Set variable $$SurveyFoundCount
- Refresh Window
- Go to Layout "Ranking Report"
- Enter Browse Mode
- Sort Records by Sub Summary Criteria
When I go to the Layout "Ranking Report" (step 7), the count of Issues for "Complex" is 106 - the total number of records in Join_Issues_mentioned with Issues in Issue field. It should be (95).
I checked the formulas and I can make this work manually but I can't get the script steps to work as described above.
Right at step 6, add in a pause/resume script step and check to see if the correct found count has been pulled up by your scripted find. Normally, one doesn't specify find criteria by entering find mode and then again with perform find. The criteria in enter find mode are being replaced by those specified in Perform Find so it's possible that your script is not finding the records that you expected.
PS. I recommend using the finds found in the following link as a model for scripted finds. It's much easier to review the criteria specified for the find when you open up the script in the script editor: Scripted Find Examples