All Collections
Asite AppBuilder
AppBuilder Sample Scripts
Pull values for a 'Dropdown' control from other forms by setting up an API connection
Pull values for a 'Dropdown' control from other forms by setting up an API connection

This is an AppBuilder Sample Script.

Updated over a week ago

Suppose there is a form type called 'Contract Data' where we are capturing contract name by adding a 'Textbox' control with the field name 'ORI_FORMTITLE'. Then there is another form type called 'Payments' where we need to show a dropdown with the field name 'Contract' containing all the contract names captured based on the forms created under 'Contract Data' form type with 'Approved' form status.

Below are the steps you need to follow for setting up an API connection to pull list of contract names for approved forms from the 'Contract Data' form type:

1. Follow the steps to setup an API connection on 'Payments' form type and enter information as follows:

Basic Information:

Name - << Enter name as 'Get Contract List' >>

API Link - << Select 'Form - Search' >>

Filters:

Project Name == << Select the concerned project where the 'Contract Data' form type is setup and from where the form information is to be received >>

Form Name == << Select the 'Contract Data' form type from where the form information is to be received >>

Form Status == << Select 'Approved' status >>

Response:

Check if the filter applied is correct and click on 'Test Run' to get the results. Going through the results for the 'Test Run' can help you find out whether the API connection created is able to retrieve the expected form information based on the filter applied.

It is advisable to copy and paste the test run results separately, in case you need to use these API connection results to define AppBuilder scripts based on form data fields returned through API.

Click 'Save' to complete setting up the API connection if the 'Test Run' is returning approved form records as expected. If you are not getting expected results, you may need to create new / update existing form data / update the filter in the API connection to get relevant results as needed.

Below are the steps to use the drag and drop code editor to define a condition upon the 'onLoad' event of 'Contract' dropdown field, in 'Payments' form type, to display the list of contract names received from the 'Contract Data' form type as a dropdown list:

1. From the left panel, go to block category 'Custom API Blocks'. Select the first block 'Select API' and drag it to the center of editor.

2. Under 'Select API Name' dropdown within the block, select the name of the API connection that we created as per above steps i.e. 'Get Contract List'.

3. From the left panel, go to block category 'Custom Functions'. Select the 'Setter' block (with the getter method) and drag it to the center adjoining the 'Select API' block as shown below.

4. In the 'Setter' block, select the control name as 'Contract'. The property name will then appear selected as 'Options'.

5. From the left panel, go to block category 'Custom API Blocks'. Select the block 'API Data' and place it opposite the 'Value' field.

6. From the left panel, go to block category 'Variables'. Select the block which returns the value of the variable and place it opposite 'API Data' field as shown below.

Here, you need to make sure the variable value selected should match the variable value showing in the 'Select API' block having the API connection selected. In the screenshot below, 'i' is the variable value which is selected under 'Select API' and matching with the 'i' variable selected under 'API Data' block.

7. Next, in the 'Select field' dropdown, select the field 'FormList.Form', then select field for option map based on the selected field. In this example, we are mapping with the field having field name 'ORI_FORMTITLE'.

8. Once done, click 'OK' (at bottom right) to save the changes and exit the code editor, then save / publish the form design as needed. Once the form design is published and executed, the changes will be applicable for the new forms created under the related form type.



Did this answer your question?