How to create conditional checkbox ?

Hi Community,

 

How can i make checkbox visible/hidden based on previous DropDown value.

For ex - I have dropdown field as Product having values - KFC, Pizzahut.

I have different checkboxes values if user selects KFC or Pizzahut.

How can i show different checbox dynamically after user selects dropdwon value.

I don't want to show all checkbox value and then hide. Based on the choice KFC/Pizzahut corresponding Checkbox options should dynamically come in form.

Here is the code that i am trying. Please help me with this.

 

    if(
          ri!readOnly,
          a!textField(
            label: "Product",
            labelPosition: "ADJACENT",
            value: ri!record.productGroupAffected.value,
            readOnly: true
          ),
          a!dropdownField(
            label: "Product",
            labelPosition: "ABOVE",
            instructions: "",
            helpTooltip: "",
            placeholderLabel: "--- Select a Value ---",
            choiceLabels: local!productGroupAffectedOptions.value,
            choiceValues: local!productGroupAffectedOptions,
            value: ri!record.productGroupAffected,
            saveInto: ri!record.productGroupAffected,
            required: false
          )
        ),
        
	
		if(
			ri!record.productGroupAffected = "KFC",
			a!textField(
			label: "Tools Affected KFC",
			labelPosition: "ADJACENT",
			value: if(
					or(isnull(ri!record.toolsAffected), count(ri!record.toolsAffected.value)=0),
					"",
				joinarray(ri!record.toolsAffected.value, ", ")
			),
			readOnly: true
			),
			a!checkboxField(
			label: "Tools Affected KFC",
			labelPosition: "ABOVE",
			instructions: "",
			helpTooltip: "",
			choiceLabels: local!checkbox1Value,
			choiceValues: local!checkbox1Value,
			value: ri!record.toolsAffected,
			saveInto: ri!record.toolsAffected,
			required: false
			)
		),
		
		if(
			 ri!record.productGroupAffected = "PizzaHut",
			a!textField(
			label: "Tools Affected PizzaHut",
			labelPosition: "ADJACENT",
			value: if(
					or(isnull(ri!record.toolsAffected), count(ri!record.toolsAffected.value)=0),
					"",
				joinarray(ri!record.toolsAffected.value, ", ")
			),
			readOnly: true
			),
			a!checkboxField(
			label: "Tools Affected PizzaHut",
			labelPosition: "ABOVE",
			instructions: "",
			helpTooltip: "",
			choiceLabels: local!checkbox2Value,
			choiceValues: local!checkbox2Value,
			value: ri!record.toolsAffected,
			saveInto: ri!record.toolsAffected,
			required: false

			)
		),
		

  Discussion posts and replies are publicly visible

Parents
  • To get a!forEach() functionality to work in 17.1 use a!apply() or a!appyComponents().
  • Hi can you suggest alternative for a!columnsLayout() and a!columnLayout() as well in 17.1 which has written for 17.2 ?
  • Here is the XSD of the CDT -

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:com:appian:types:CCCD" targetNamespace="urn:com:appian:types:CCCD">
      <xsd:complexType name="CCC_Details">
        <xsd:annotation>
          <xsd:documentation><![CDATA[Information]]></xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
          <xsd:element name="CCCNumber" nillable="true" type="xsd:int">
            <xsd:annotation>
              <xsd:appinfo source="appian.jpa">@Id @GeneratedValue</xsd:appinfo>
            </xsd:annotation>
          </xsd:element>
          <xsd:element name="Approved" nillable="true" type="xsd:string">
            <xsd:annotation>
              <xsd:appinfo source="appian.jpa">@Column(length=50)</xsd:appinfo>
            </xsd:annotation>
          </xsd:element>
          <xsd:element name="ApprovalDate" nillable="true" type="xsd:date" />
          <xsd:element name="PRNumber" nillable="true" type="xsd:int" />
          <xsd:element name="ProductGroupAffected" nillable="true" type="xsd:string" />
          <xsd:element maxOccurs="unbounded" minOccurs="0" name="ToolsAffected" nillable="true" type="xsd:string" />
          <xsd:element maxOccurs="unbounded" minOccurs="0" name="NodesAffected" nillable="true" type="xsd:string" />
          <xsd:element name="ApprovedBy" nillable="true" type="xsd:string">
          
          <xsd:element name="Bundled" nillable="true" type="xsd:string">
            <xsd:annotation>
              <xsd:appinfo source="appian.jpa">@Column(length=5)</xsd:appinfo>
            </xsd:annotation>
          </xsd:element>
          <xsd:element name="CreatedBy" nillable="true" type="xsd:string">
            <xsd:annotation>
              <xsd:appinfo source="appian.jpa">@Column(length=100)</xsd:appinfo>
            </xsd:annotation>
          </xsd:element>
          <xsd:element name="CreatedOn" nillable="true" type="xsd:dateTime" />
          <xsd:element name="UpdatedBy" nillable="true" type="xsd:string">
            <xsd:annotation>
              <xsd:appinfo source="appian.jpa">@Column(length=100)</xsd:appinfo>
            </xsd:annotation>
          </xsd:element>
          <xsd:element name="UpdatedOn" nillable="true" type="xsd:dateTime" />
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>

  • 0
    Certified Lead Developer
    in reply to prais1852
    I don't really need an XSD, just maybe a description of how some of the CDT properties you're using are configured (such as NodesAffected for instance), or maybe a screenshot. And also you didn't mention what error you're getting.
  • My problem is same as earlier. Still if i click one of the Nodes Affected ( Product Sizes in earlier examples ) and then select the some other from list of checkboxes, my previous selection gets removed. However it is working fine for the code you mentioned above using local variables but not working with rule inputs.

  • Hi on saving values in rule input it is not working compared to the above code written by you. Is there any other way to store the data with item & sizes pair ?
  • Hi It works only when i click all the checkboxes before page reloads with selected options. I checked on the interface also. The values are getting inserted in the interface input but once i click on any other text field of my form the checkbox selection gets removed.

    If you can explain the use of property() in your code then that will also be very helpful. I am not getting the idea why you have used property method.
  • 0
    Certified Lead Developer
    in reply to prais1852
    I really can't help much more if you can't give me some further details about your exact configuration including screenshots of your SAIL rule input configurations, etc. Have you tried reverting to the working code I'd posted, and try replacing local variables with Rule Inputs one at a time and making sure it works at each step?

    Also, you need to get familiar with the support documentation available here - for example the property function is described here: docs.appian.com/.../fnc_scripting_property.html -- in short, the property() function is used to extract a "property" (as in "dot property") from a CDT or Dictionary, in a safe manner such that a default output can be returned if the property doesn't exist (i.e. if ri!myUser.firstName doesn't exist, property(ri!myUser, "firstName", "none") will return "none").
  • Hi  Thank you for your help. Here are the details - 

    Something like the below attached screenshot i am trying to achieve on my interface -

    Where Product Group Affected has a dropdown value coming from constant, Tools affected values are coming from an expression rule based on Product Group affected selection and finally foreach() loop for Nodes Affected for each Tool. But Nodes Affected checkbox selections are not working for me. Below is the code for it which i am using by replacing local variables with rule input.

    a!dropdownField(
        		label: "Product Group Affected",
        		labelPosition: "ABOVE",
        		placeholderLabel: "--- Select a Value ---",
        		choiceLabels: cons!CCCProductGroupAffectedOptions,
        		choiceValues: cons!CCCProductGroupAffectedOptions,
        		value: ri!CCC.ProductGroupAffected,
        		saveInto: {
          		ri!CCC.ProductGroupAffected,
        		/* the below will clear the previous Tools Affected Selection when the Product Group Affected is changed */
                  		a!save(
                    		ri!CCC.ToolsAffected,
                    		{}
                  		)
                 		},
        		validations: {}
      		),
    		
      		a!checkboxField(
        		label: "Tools Affected",
        		labelPosition: "ABOVE",
            choiceLabels: rule!CCCToolsAffectedOptions(ri!CCC.ProductGroupAffected),
            choiceValues: rule!CCCToolsAffectedOptions(ri!CCC.ProductGroupAffected),
        		value: ri!CCC.ToolsAffected,
        		saveinto: ri!CCC.ToolsAffected,  
            /*ChoiceLayout: "COMPACT",/*STACKED*/
        		showwhen: not(isnull(ri!CCC.ProductGroupAffected)),
        		validations: {}
        		),
    			a!columnsLayout(
    			columns: a!forEach(
    				ri!CCC.ToolsAffected,
    				with(
    					local!currentIndex: wherecontains(
    					fv!item,
    					touniformstring(property(ri!CCC.NodesAffected, "Tool", {}))
    				),
    		
            a!columnLayout(
    					contents: {
              	a!checkboxField(
                  label: "Nodes Affected for : '" & fv!item & "'",
                  labelPosition: "ABOVE",
                  /*instructions: "current index: " & local!currentIndex,*/
                  choiceLabels: cons!CCCNodesAffectedOptions,
                  choiceValues: cons!CCCNodesAffectedOptions,
                  value: tointeger(
                  property(
                      index(
                        ri!CCC.NodesAffected,
                        local!currentIndex,
                        null()
                       ),
                       "Nodes",
                       null()
                     )
                   ),
                   saveInto: {
                     a!save(
                       ri!CCC.NodesAffected,
                         append(
                           if(isnull(local!currentIndex),
                             ri!CCC.NodesAffected,
                             remove(ri!CCC.NodesAffected, local!currentIndex)
                            ),
                            if(
                                rule!APN_isEmpty(save!value),
                                /* indicates all size choices have been de-selected, so we'll save an empty set here to remove this menu choice from the saved data set */
                                {},
                                {
                                  Tool: fv!item,
                                  Nodes: save!value
                                }
                              )
            							)
          						)
        						}
      						)
        				}
      				)
      			)
      		),
    		  showwhen: not(isnull(ri!CCC.ProductGroupAffected))
    		),
    	

    I am using a interface input named CCC of type CDT. To get the checkbox values Tools Affected and Nodes Affected i have made as an Array.

    Let me know if you need any other information. I tried a lot to debug the issue but wasn't able to figure out and looking for help. 

  • 0
    Certified Lead Developer
    in reply to prais1852
    Sorry, was a bit busy today - i'll try to take a look at it tomorrow.
  • 0
    Certified Lead Developer
    in reply to prais1852

     First of all, migrating from Higher Version to Lower version is never a good approach. Because this require lot of changes to be done in your application.

    Now coming back to your requirement, there are no alternative for a!columnsLayout(). Till 17.1 version, we had max 2 columns for each UI, while UI designing, whereas from 17.2 on-wards a!columnsLayout() added more flexibility to have multiple columns as per our need.

    So, if you have switched from 17.2 to 17.1, i recommend change your layouts and their contents. And also replace all those functions which are introduced in 17.2 with their similar one in 17.1 as already been discussed above

Reply
  • 0
    Certified Lead Developer
    in reply to prais1852

     First of all, migrating from Higher Version to Lower version is never a good approach. Because this require lot of changes to be done in your application.

    Now coming back to your requirement, there are no alternative for a!columnsLayout(). Till 17.1 version, we had max 2 columns for each UI, while UI designing, whereas from 17.2 on-wards a!columnsLayout() added more flexibility to have multiple columns as per our need.

    So, if you have switched from 17.2 to 17.1, i recommend change your layouts and their contents. And also replace all those functions which are introduced in 17.2 with their similar one in 17.1 as already been discussed above

Children