how to store the child CDT field in parent CDT using Ruleinput in the interface.?(one to many-flat relation)

Certified Associate Developer

Hi All,

I have inserted the interface code, comment field line :152, here how can we pass the ruleinput to value and saveinto parameter.?

thanks in advance.

a!localVariables(
  local!griddata: 'type!{urn:com:appian:types:IA}IA_asupplier'(),
  local!selection: ri!addProduct.status,
  local!comments,
  
  a!formLayout(
    label: if(
      ri!Manager = true,
      "Approval for Product",
      "Add Product Details"
    ),
    contents: {
      a!sectionLayout(
        label: "",
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!dropdownField(
                    label: "Product Name",
                    labelPosition: "ABOVE",
                    placeholder: "---  Select a Value ---",
                    choiceLabels: cons!IA_ProductName,
                    choiceValues: cons!IA_ProductName,
                    value: ri!addProduct.productname,
                    saveInto: ri!addProduct.productname,
                    searchDisplay: "AUTO",
                    required: true,
                    disabled: ri!Manager = true(),
                    validations: {}
                  ),
                  a!dropdownField(
                    label: "Category Type",
                    labelPosition: "ABOVE",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: cons!IA_CategoryType,
                    choiceValues: cons!IA_CategoryType,
                    value: ri!addProduct.categoryType,
                    saveInto: { ri!addProduct.categoryType },
                    searchDisplay: "AUTO",
                    required: true,
                    disabled: ri!Manager = true(),
                    validations: {}
                  ),
                  a!paragraphField(
                    label: "Product details",
                    value: ri!addProduct.productdetails,
                    saveInto: { ri!addProduct.productdetails },
                    required: true,
                    disabled: ri!Manager = true()
                  )
                }
              ),
              a!columnLayout(contents: {})
            }
          )
        }
      ),
      a!gridLayout(
        label: "Supplier Details",
        labelPosition: "ABOVE",
        headerCells: {
          a!gridLayoutHeaderCell(label: "Name of Supplier"),
          a!gridLayoutHeaderCell(label: "Quantity"),
          a!gridLayoutHeaderCell(label: "Location"),
          a!gridLayoutHeaderCell(label: "PhoneNumber"),
          a!gridLayoutHeaderCell(label: "")
        },
        columnConfigs: {
          a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
          a!gridLayoutColumnConfig(width: "ICON"),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
          a!gridLayoutColumnConfig(width: "ICON")
        },
        rows: {
          a!forEach(
            items: ri!addProduct.supplierDetails,
            expression: a!gridRowLayout(
              contents: {
                a!pickerFieldUsers(
                  maxSelections: 1,
                  groupFilter: cons!IA_SupplierGroup,
                  value: fv!item.suppliername,
                  saveInto: fv!item.suppliername,
                  required: true,
                  readOnly: ri!Manager = true
                ),
                a!integerField(
                  value: fv!item.quantity,
                  saveInto: fv!item.quantity,
                  required: true,
                  validations: if(
                    tointeger(fv!item.quantity) <= 0,
                    "Please enter greater than 0",
                    {}
                  )
                ),
                a!textField(
                  value: fv!item.location,
                  saveInto: fv!item.location,
                  readOnly: ri!Manager = true
                ),
                a!textField(
                  value: fv!item.phoneNumber,
                  saveInto: fv!item.phoneNumber,
                  readOnly: ri!Manager = true
                ),
                a!richTextDisplayField(
                  value: a!richTextIcon(
                    icon: "times",
                    link: a!dynamicLink(
                      saveInto: a!save(
                        target: ri!addProduct.supplierDetails,
                        value: remove(ri!addProduct.supplierDetails, fv!index)
                      )
                    ),
                    showWhen: ri!Manager = false,
                    color: "NEGATIVE"
                  )
                )
              }
            )
          )
        },
        addRowLink: a!dynamicLink(
          label: "Add Suppplier",
          saveInto: a!save(
            target: ri!addProduct.supplierDetails,
            append(
              ri!addProduct.supplierDetails,
              local!griddata
            )
          ),
          showWhen: ri!Manager = false()
        ),
        validations: {},
        shadeAlternateRows: true
      ),
      a!radioButtonField(
        label: "Status",
        labelPosition: "ABOVE",
        choiceLabels: cons!IA_StatusARR,
        choiceValues: cons!IA_StatusARR,
        value: ri!addProduct.status,
        saveInto: ri!addProduct.status,
        showWhen: ri!Manager = true(),
        choiceLayout: "STACKED",
        validations: {}
      ),
      a!paragraphField(
        label: "Reason/Comments",
        labelPosition: "ABOVE",
        value:local!comments,
        saveInto:ri!addProduct.multicomments.comments,
        refreshAfter: "UNFOCUS",
        height: "MEDIUM",
        showWhen: or(
          local!selection = "Reject",
          local!selection = "Return"
        ),
        required: true,
        readOnly: if(
          'recordType!{fb9fc1c0-b1ff-43a2-aea6-c4a11b2d7bbe}IA AddProduct.fields.{ed9bcd81-5050-4eaa-90b9-f18c43a669ee}status' = "Return",
          true,
          false
        )
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          saveInto: ri!addProduct.activeStep,
          value: if(ri!addProduct.status = "Approve", 3, 2),
          submit: true,
          style: "PRIMARY"
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: if(ri!Manager = true, "Submit", "Cancel"),
          value: true,
          saveInto: ri!cancel,
          submit: true,
          style: "NORMAL",
          showWhen: ri!Manager = false(),
          validate: false
        )
      }
    )
  )
)

child cdt 

parent cdt

  Discussion posts and replies are publicly visible

  • Hi there, 

    Your multiComments field of your parent CDT is of type another CDT that too list. Now because it is a list, you need to decide on which index do you want to store the comment. Either you build it is a loop so user can add multiple comments, or you make it single instead of list in the CDT or you need to fetch the existing comments from the DB and then use the next available index to store the values. 

  • In cases like this where you must construct the data structure to match, I almost always use a local variable to save the initial value and then define the CDT on button click to format the data how the CDT expects it. To do this, you just save into a local variable in your paragraph field and then use a type constructor CDT to save your results into your parent CDT. Something like this should do the trick for the paragraph field:

    a!paragraphField(
      label: "Reason/Comments",
      labelPosition: "ABOVE",
      value:local!comments,
      saveInto: local!comments,
      refreshAfter: "UNFOCUS",
      height: "MEDIUM",
      showWhen: or(
        local!selection = "Reject",
        local!selection = "Return"
      ),
      required: true,
      readOnly: if(
        'recordType!{fb9fc1c0-b1ff-43a2-aea6-c4a11b2d7bbe}.fields.{ed9bcd81-5050-4eaa-90b9-f18c43a669ee}' = "Return",
        true,
        false
      )
    )

    Then, you can construct the appropriate CDT on the button like this:

    a!buttonWidget(
      label: "Submit",
      saveInto: {
        a!save(
          target: ri!addProduct.activeStep,
          value: if(ri!addProduct.status = "Approve", 3, 2)
        ),
        a!save(
          target: ri!addProduct.multicomments,
          value: type!IA_Comments(
            comments: local!comments
          )
        )
      },
      submit: true,
      style: "PRIMARY"
    )

  • 0
    Certified Associate Developer
    in reply to Peter Lewis

    Thanks Peter, it works like charm.

  • 0
    Certified Associate Developer
    in reply to Peter Lewis

    when ever the new entity get saved, the old entity automatically deleted.   how can we set doesn't reset the value.

    for ex: here the18 entiy deleted.

  • I'm not sure I follow, are you saying that rows 13 and 16 used to have data for the comments, but now that's being cleared out when you write? Are you trying to save a list of comments together? If so, what does the value for your rule input look like on the form?

  • 0
    Certified Associate Developer
    in reply to Peter Lewis

    here the problem is Updating the comments value ,but we need to store the multiple comments  with new ID.

    flow: when the manager select:return with comments the flow goes back to Shopkeeper he edit the things once submit,again the same instance retive to manager still he return that instance with new comments like( Activity chain)  

  • I'm sorry, I don't think I understand what the issue is. Are you saying that you're trying to update existing comments but it isn't working? Or that you're trying to add comments and it isn't working? Can you give an example (with data) of what you provided to the inputs, what output you received and what you expected?

  • 0
    Certified Associate Developer
    in reply to Peter Lewis

    first commend added in Tabel.

    the flow will open by shopkeeper and add the supplier and submit, 

    now the same instance task open by manager again return the task. with  new comments 

    the old comment will updating with new one..

    how can persist all the comments in that instance.

  • At a basic level, you have to make sure that you don't provide the comment with the same ID to the second form. One way of approaching this is to append a new item to your CDT list and refer to that second item in your form - you can directly save into the second item like this:

    a!save(
      target: ri!addProduct.comment[2],
      value: ri!addProduct.comment[2]
    )

    That being said, now that I see this whole flow it does make me somewhat question this design. Do you expect to always have exactly two comments (to represent the initial form and manager? If so you might want to think about either storing these as two separate fields on the base record or adding an additional field into your comments record that specifies the type of comment that is added.