After reading this article, you will know:

  • What custom models are.
  • How to create custom models.
  • Where to use custom models.

Custom Models

A custom model is a model that's isn't implemented in your data model. It is used to store sets of data in an object instead of using multiple loose variables. This means that they are great for purposes like data transmission and keeping your variables organized!  You can find all your custom models via Tools > Custom models.

Usage

There’s multiple ways to create a custom model. You can make one by simply creating one manually on the custom models page, or you can create one based off a JSON response from a web service. If you want to learn more about creating custom models, you can find a good tutorial here: HowTo create a custom model?

You can use custom models in endpoints and actions as a source of input and output of data. This is a great way to trim down your input variables by turning them all into one custom model instead.

Endpoints

When your endpoint contains a form of data input (e.g. a form), you can save this as a single custom model instead of several different variables. This is great when trying to use said data in an action, as it’s all conveniently clustered. 

POST page

When creating your POST page, you can use a custom model to capture all fields in a single input variable. This is a great way to keep your application’s structure simple. 

If you don't know what form-pages and POST page are, make sure to read What are GET & POST pages or HowTo create a form page.

If you go to your POST page and add a new input variable, you can choose a custom model as a type. Here you can select one of the models you’ve made previously or create a new one.

If you’re making a new one, it’ll ask you to select all the properties you’d like it to copy from the model it’s based on. 

When you're done and have saved the POST page, you can access your custom model as an object in your action!

GET page

You can use custom models to accept the data from a form. This is great for giving yourself a single entity you can reference for the results of the form. The syntax for this is custom_modelname[attribute]

So when you've got a custom model, based on your Contact model, named cm _contact and you've named the model's property first_name, your input tag will have to look something like this:

When you give your input fields the proper name, you’ll be able to find the variable on the post page, inside of the custom model you set as an input variable (and used the name of in your GET page).

Webservice custom models.

When you're testing your webservice, you can create a custom model containing all the data from the response with only one click on the button.

When you click Generate custom model, one custom model will be created, based on the response's body. The custom model attributes try to find their own type, which may even be another (nested) custom model. You're able to edit these types if you don't agree with the given type.

This custom model can now be used in actions. It makes building a webservices a lot quicker because you won't have fetch every single variable using text expressions, which is also very much prone to error.

Derived custom models

Derived custom models are custom models based on (derived from) existing models from your datamodel.

Derived custom models can be created as input variables, and can come in handy when building form pages with multiple input fields.

Let's say you've got a registration form for your contacts and you've got a Contact model with the properties firstname, lastname, email, address, zipcode and city. You'll create a registration page which will look something like this:

This example comes from a template, also available for you!

Did this answer your question?