How to use a function in expression in Mobile application

Hi,

I have an expression where i need to populate the Username of an User by his Passing his ID as a parameter.

For this, 

  1. I created a server action(GetUserNameById_Server) to call user aggregate with a filter as User.Id=userid(parameter). 
  2. Then, I made a client action(GetUserNameById_Client) and called this (GetUserNameById_Server) action in it
  3. Made GetUserNameById_Client as function
  4. When i now try to call this GetUserNameById_Client function in Expression wizard, i am getting error.


Can anyone help me achieving this

Solution

Hi Venkata,

First, when you have questions about an error, always say what the error is. This will help tremendously in troubleshooting. However, in this case I know what the error is, it's something like "Invalid Client Function
'XXXX' cannot be used in 'XXXX' because server actions are not available in client functions. Change the 'Function' property of the action 'Action1' to 'No'." And it very clearly states what is the problem: "server actions are not available in client functions". There's a good, but complicated, technical reason for that (I forgot which, but was once told by an OutSystems engineer), but it is what it is: what you want is just not possible.


Solution

When trying to call a client function in view you can't call a client function with a server-side function in it.


What you could do:


  1. Add a Data Action in the Web block or Screen.
  2. Call the GetUserNameById_Server inside the DataAction
  3. Add an output parameter to the Data Action.
  4. Assigned the result of the GetUserNameById_Server in the created output parameter.
  5. Use the output parameter in your view or expression.


Jovvy wrote:

When trying to call a client function in view you can't call a client function with a server-side function in it.


What you could do:


  1. Add a Data Action in the Web block or Screen.
  2. Call the GetUserNameById_Server inside the DataAction
  3. Add an output parameter to the Data Action.
  4. Assigned the result of the GetUserNameById_Server in the created output parameter.
  5. Use the output parameter in your view or expression.


 Thanks if I follow the above can I also add an input parameter to the data action?


 

Hi Abid,

Note that the above is a crude work-around, that likely comes with a performance penalty, so you might want to think twice before using it. Also, they run asynchronously, so if the server is slow to respond, the answer may not even be available. It is definitely not something you'd want to use to replace all Functions in Reactive/Mobile.

As for your question, no, it's not possible to pass parameters to Data Actions. As I said, they are meant to run asynchronously when the Screen starts, so there's no way to pass a Parameter.

Kilian Hekhuis wrote:

Hi Abid,

Note that the above is a crude work-around, that likely comes with a performance penalty, so you might want to think twice before using it. Also, they run asynchronously, so if the server is slow to respond, the answer may not even be available. It is definitely not something you'd want to use to replace all Functions in Reactive/Mobile.

As for your question, no, it's not possible to pass parameters to Data Actions. As I said, they are meant to run asynchronously when the Screen starts, so thereCommunity's no way to pass a Parameter.

 Hi Kilian, 

Thanks for getting back to me and your explaination it makes sense and is clear. 

Hope you can guide me on the following : 

I have a table based on a aggregate on my interface, and in a row cell I have an expression. 

The desired output of the expresssion is to have to have the number of Links associated with each Product, which is represended by a row on the table. 

In the expression I want to call a function called say for example 'CountOfLinksForProduct(ProductId)' which takes a Integer as a paramenter for ProductId and then returns a total count of the Links to that Product. 

Inside the function I simply run an aggrate on a table called LinkedProducts use the parameter supplied as the Filter to match all links on ProductID. 

I assign the result query count to the OutPut parameter of the function  CountOfLinksForProduct, so that the original expression gets and displayes the results. 

Note : I'm trying to encapsulate some data behind server functions ideally in another reusable module. 

So the above is what I want to do. 

I've tried the following (with the dead ends I've hit): - 

1. Server Actions (cant used indentifiers that are not public, so I used Intergers) but I cannot use server actions in Cliend 

2. On Interface: Get Data from other Source/Data Actions (do no allow Input Parameters)

3. On Interface : Client Actions (do not allow Output Parameters) 

4. On Logic : Client Actions (have Input and Output but don't allow server fucntion and nor do they have tables/aggragates so I need to call a Server Action) And if I se the 'Function' to 'No' then the function cannot be found in the expression. 

Anyway seems like everything I've tried above has a dead end so wanted to see if you have directions you can offer. 

(I hope the above is clear) 

Regards,

Abid