Hi,

 I have to show the input fields on the page based on API response.

For example, below is the API response 

fields:[
{
"field":"Username",
"type":"textfield"
},
{
"field":"Password",
"type":"textfield"
}
]

Here, Api contains list of objects. First object contains field and type. So, I have to display the lable name as Username("field":"Username") and filed type is textfield("type":"textfield"). But, one more thing is sometimes API may return 5 fields(Address, Phonenumber and etc) instead of 2 fields. So based on API response, I have to show all the fields on the page.


Hi divya,

I'm sure you are not expecting us to provide a ready solution, so I'll assume that you forgot part of your question.

I'll help with that.

1. What did you make so far? I assume you are using a list to show the inputs and web blocks to build them, or something in those lines.

2. What is the problem you're facing?

Cheers

Hi Eduardo,

Thanks for your reply.

Actually, I have exposed one API in Outsystem.  The response of that API is 

fields:[
{
"field":"Username",
"type":"textfield"
},
{
"field":"Password",
"type":"textfield"
}
]

I want to display the two input fields(Refer below attached image) on the page based on the above API response.  I have to display the label and field(can be a combo box, text field and etc)But, I am too confused that whether we will be able to do it in Outsysytem or not. 




Hi,

Yes, you are able to do this in OutSystems.

But if you don't know how to do it, even with my hint in the previous answer, I recommend you to take the online training if you didn't yet, or review the part about lists and web blocks if you already.

You can also google it around as probably there is more than one topic about this in OutSystems.

When you have the main idea and already played a little with it, come back if you have any problem.

Cheers

P.S. You can also wait to see if someone with more time can provide you with a gull solution

P.S. 2 I remember seeing something related in the Forge. You may want to look in there.

Hi,

Yes, you are able to do this in OutSystems. 

Simple solution: After you receive the JSON through your REST call, you can extract all the information you need from your JSON and put them into variables, then pass these variables to a webblock with some if-statements and expressions for labels.

Less simple solution: If the number of possible received fields exceeds the effort you want to spend on if statements or if you are unsure of yourself, you can search the Forge for an OutSystems component or get a JavaScript library from the web and integrate it into your application.

In both cases, I suggest you take the online training first before deciding upon your solution.

Hello @Monique,

I still think the simplest solution would be to put the JSON into a LIST and provide it to a List Records in the screen, in a dynamic way. If it is the response for an API Method, it will be already in a LIST format, if not, you can Deserialise with the Deserialize Json statement in logic.

The list then would switch the input based on the possible types (would not be a big number, probably), and use web blocks to construct the correct input.

Yet, I think I saw a component to do this in Forge... But I'm not sure.

Cheers.