Global function to work with out all parameters
Is it possible to have a global function that works with out having all parameters defined? Right now I can't see a way, but I'm just diving into global functions.
I have a sports DB and there are many calculations that are similar so I'm finally trying out global functions.
I have a function that is pretty simple:
function teamAvP(tID : number,yNum : number) do
avg((select Results)[TeamID = tID and Year_calc = yNum].Penalty4Average_Count)
end
I want to be able to use this function to find all results of a tID and sometimes use the yNum parameter. I have a few more parameters that I want to throw in, but this is a good start.
Thanks,
12 replies
-
It is not possible to set default parameters or omit a parameter when calling a function. Ninox expects the right number of parameters with the right type for each.
But you can call a function with one (or more) parameters with a null value:
teamAvP( this.id, number(void) );
So, in your global function, you check if yNum is void or not. You have several ways to do this. Here are two examples :
- create a test with two different processes :
function teamAvP2(tID : number,yNum : number) do if (ynum = void) then avg((select Results)[TeamID = tID].Penalty4Average_Count) else avg((select Results)[TeamID = tID and Year_calc = yNum].Penalty4Average_Count) end; end
- include your test in the where clause (yNum = void or Year_calc = yNum) :
function teamAvP2(tID : number,yNum : number) do avg((select Results)[TeamID = tID and (yNum = void or Year_calc = yNum)].Penalty4Average_Count) end;
-
Ok, how does one do a null in a text field?
I have this global function:
function teamAvP(tID : number,yNum : number,cName : text,rType : text) do avg((select Results)[TeamID = tID and (yNum = void or Year_calc = yNum) and (cName = void or 'City Name' = cName) and (rType = void or 'Round Type' = rType)].Penalty4Average_Count) end;
I want to leave rType, the 4th parameter, empty. So I've tried:
let xY := record(Seasons,number(Season)); teamAvP(Team.TeamID, xY.Year, City.'City Name', "")
All other parameters are based on field selections either from dynamic choice or reference field. the rType is the only one that is hand coded.
I've tried:
""
text(void)
text(null)
None of the above work. What are my other options?
-
Jacques TUR said:
Can you tell me more so I know where to look?Ok, so I have this global function:
function teamAvP(tID : number,yNum : number,cName : text,rType : text) do avg((select Results)[TeamID = tID and (yNum = void or Year_calc = yNum) and (cName = void or 'City Name' = cName) and (rType = void or 'Round Type' = rType)].Penalty4Average_Count) end;
When I try any of the following for the 4th parameter I get an empty field:
let xY := record(Seasons,number(Season)); teamAvP(Team.TeamID, xY.Year, City.'City Name', "") or teamAvP(Team.TeamID, xY.Year, City.'City Name', text(void)) or teamAvP(Team.TeamID, xY.Year, City.'City Name', text(null))
If I put in a value I get results:
let xY := record(Seasons,number(Season)); teamAvP(Team.TeamID, xY.Year, City.'City Name', "1")
All other parameters are based on field selections either from dynamic choice or reference field. the 4th parameter (rType) is the only one that is hand coded.
-
Jacques TUR said:
Does it work when you call teamAvP with void in the cName parameter?cName doesn't work if I hard code text(void), but since the data comes from a reference field it seems to work fine without the cName = text(void).
I'm sorry, my eyes glazed over the rType = text(void) changes you made. That was the solution staring me in the face. Thanks for being patient with me.
Content aside
- Status Answered
- 2 yrs agoLast active
- 12Replies
- 338Views
-
2
Following