Default values on fields in form

I am passing a CDT in to a form. ri! input. The form has like 6 fields. The user can enter data and it gets saved to the cdt fields.

 

However, how can I make one of the fields have a default value?

 

For example, I want one of the fields to, by default, have English already selected so the users dont have to select it from the dropdown...so its always English, unless they want to change it.

 

Any suggestions.

 

Thanks,

  Discussion posts and replies are publicly visible

  • There are two ways I typically accomplish this. One is to set the values in the fields of the CDT in the process before it is passed in as a node input. The other is to create a local variable or variables that are set to a default value when the form is loaded. The fields on the form then use those local variables as their values and save into them. Then, when a submit button or link is pressed, the values of those local variables are saved into the rule inputs.

  • Adding onto what gianninol mentioned, I have found that the first method is preferable as it simplifies the logic contained within the interface and allows it to be reusable across a number of use cases (such as a new form or editing an existing one). It also allows for some interesting manipulations from the Data Inputs and Data Outputs such as including only certain fields.
    However, there are cases where this method isn't possible or not feasible. For instance, say you're pulling in an employees details through an API to prepopulate a start form. If these details are stored across multiple variables, you would have to call the API multiple times as each parameter is defined simultaneously. In this case, the second method is preferable as the API would only be called once, but it would require additional logic to *not* call the API if the data already exists.
    As such, I would implement the first method and implement the second where the first is not possible.
  • By default, to store the value in a field when the form is loaded then it is preferable to use local variables, defined the default value at value parameter of field and to save that particular value into rule input you need to define the code in saveInto parameter of Submit button on click action so that the value will be saved into the rule input of CDT.
  • Please share sample code to set default value for local variables in an interface. Thank you.

  • While passing the CDT, pass it as below:

    'type!{urn:com:appian:types}CDT_NAME'(
      field1: "",
      field2: "",
      language: "English"
    )