Hi,
I am trying to write a function that will go through a set of records and sum a given field (Field B) if criteria for another field is met (Field A). So if Field A = "Yes" then add Field B to a sum.
Below is a function I use to sum all the values in Field B (Man_Months in this case):
- float TotalJobsCon()
- {
- countMonths = 0.0;
- for each r in JobCreationSchedule [Man_Months != 0]
- {
- countMonths = (countMonths + r.Man_Months);
- }
- return countMonths;
- }
This works perfectly because Man_Months is a float type field.
But When I adapt the function to sum only those fields that fit the criteria I am looking for, I get errors:
- float SkilledJobs()
- {
- countMonths = 0.0;
- for each r in JobCreationSchedule [Skill_Level == "Skilled"]
- {
- countMonths = (countMonths + r.Man_Months);
- }
- return countMonths;
- }
In fact, when I use the script builder to create the "for each record" snippet, it shows an error saying that Man_Months is a string and I cannot proceed. But it isn't, and the previous function works very well!
Please tell me what I am doing wrong.
Thanks,
Gericke