Add multiple values to the interface and store them in DB

Certified Associate Developer

Hi Community Team,

I'm facing issue to store multiple values in Database, My task is to accomplish to add multiple comments in a interface section layout. I need to store them by saving them into Cdt. 

User Scenario: For each comment it needs to generate new Primary Key.. Data need to be entered in a new row for each comment.

Comments  
Comment1 Remove Icon
Comment2 Remove Icon
comment 3 Remove Icon
Add Icon to add new comment

  Discussion posts and replies are publicly visible

Parents
  • You only described the scenario, can you explain in detail what is the issue you are facing and what have you tried ?

  • 0
    Certified Associate Developer
    in reply to Sanchit Gupta (Xebia)

    LOL Joy  I'm getting errors while configuring to save the comments in DB. The storing unusual format and I'm getting only One PK for all comments, instead I need to get Multiple PK's for multiple comments. 

    I had given the input as: 

    Hi 

    Good day

  • 0
    Certified Associate Developer
    in reply to Sanchit Gupta (Xebia)

    a!gridLayout(
          label: "Add Comments",
          emptyGridMessage: "No Comments Added",
          headerCells: {
            a!gridLayoutHeaderCell(
              label: "Comments"
            ),
            a!gridLayoutHeaderCell(
              label: ""
            )
          },
          columnConfigs: {
            a!gridLayoutColumnConfig(
              width: "DISTRIBUTE"
            ),
            a!gridLayoutColumnConfig(
              width: "ICON"
            )
          },
          rows: a!forEach(
            items: ri!mention,
            expression: a!gridRowLayout(
              id: fv!index,
              contents: {
                a!textField(
                  label: "No" & fv!index,
                  labelPosition: "ABOVE",
                  value: fv!item.mention,
                  saveInto: fv!item.mention,
                  validations: {},
                  align: "CENTER"
                ),
                a!imageField(
                  label: "delete " & fv!index,
                  images: a!documentImage(
                    document: a!iconIndicator(
                      "REMOVE"
                    ),
                    altText: "Comment " & fv!index,
                    caption: "Comment " & fv!index,
                    link: a!dynamicLink(
                      value: fv!index,
                      saveInto: {
                        a!save(
                          local!arrayVal,
                          remove(
                            local!arrayVal,
                            save!value
                          )
                        )
                      }
                    )
                  ),
                  size: "ICON"
                )
              }
            )
          ),
          addRowlink: a!dynamicLink(
            label: "Add new comment",
            value: {
              comments: "" 
            },
            saveInto: {
              a!save(
                local!arrayVal,
                append(local!arrayVal,
                  save!value
                )
              )
            }
          )
        )

  • Assuming ri!mention is of Comment CDT type. Your code should look like this:

    a!gridLayout(
      label: "Add Comments",
      emptyGridMessage: "No Comments Added",
      headerCells: {
        a!gridLayoutHeaderCell(label: "Comments"),
        a!gridLayoutHeaderCell(label: "")
      },
      columnConfigs: {
        a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
        a!gridLayoutColumnConfig(width: "ICON")
      },
      rows: a!forEach(
        items: ri!mention,
        expression: a!gridRowLayout(
          id: fv!index,
          contents: {
            a!textField(
              label: "No" & fv!index,
              labelPosition: "ABOVE",
              value: fv!item.mention,
              saveInto: fv!item.mention,
              validations: {},
              align: "CENTER"
            ),
            a!imageField(
              label: "delete " & fv!index,
              images: a!documentImage(
                document: a!iconIndicator("REMOVE"),
                altText: "Comment " & fv!index,
                caption: "Comment " & fv!index,
                link: a!dynamicLink(
                  saveInto: a!save(ri!mention, remove(ri!mention, fv!index))
                )
              ),
              size: "ICON"
            )
          }
        )
      ),
      addRowlink: a!dynamicLink(
        label: "Add new comment",
        saveInto: {
          a!save(
            ri!mention,
            append(ri!mention, type!CommentCDT)
          )
        }
      )
    )

  • 0
    Certified Associate Developer
    in reply to Sanchit Gupta (Xebia)

    HI  thanks for quick responses, I'm getting error while I'm trying to add comment. ri!mention is my rule input which refers to my type as CDT which is Array "Multiple Values". I tried with unchecking the array in my rule input, then I clicked on dynamic link to add it reflects nothing.

    Error in a!forEach() expression during iteration 1: Expression evaluation error at function a!textField [line 384]: Invalid index: Cannot index property 'mention' of type Text into type CT_Comments_ID

  • You need to reference the field correctly where you are using fv!item.mention. Make sure that the key you are using is same in the CT_Comments_ID CDT , copy the field name from CDT and paste it in the expression.

    FYI, you have mentioned someone else in the comment.

  • 0
    Certified Associate Developer
    in reply to Sanchit Gupta (Xebia)

    Hope, I mentioned you this time correctly   got your Point and made changes accordingly and now I'm seeing the changes without any errors in the Interface Cdt values. It is like as follows:  Example

    After executing the process through PM,  I have passed two comments, But, I'm able to retrieve only one comment with one PK and FK in my DB. Reference

    In my use Case I want to generate one Foreign Key and generate multiple Primary Keys for multiple comments. The comments needs to come in a new row in DB. Like as follows:

    COMMENT_ID (PK) REQUEST_ID (FK) ADD_COMMENT
         1       1    COMMENT1
         2       1    COMMENT2
         3       1    COMMENT3

     I have to achieve my user case like this.. Can you let me know how I can achieve this? 

    Thanks in advance...

  • You need to set the requestId in your comment CDT, you can do that in the process or I would suggest changing the save in addRowLink like:

    a!save(
      ri!mention,
      append(
        ri!mention,
        type!CommentCDT(
          requestId: ri!requestId/*ri! or localVariable in which you are having requestId*/
          
        )
      )
    )

    If you are writing to the request table after form submission then update the value in requestId of Comment Cdt with the generated primary key of Request table.

    And for writing multiple entries make sure that the node input for the entity in WDSE is of multiple type.

  • 0
    Certified Associate Developer
    in reply to Sanchit Gupta (Xebia)

    Hi, I tried like what you said, I'm getting an error like this  when I clicked on add new comment:

    xpression evaluation error [evaluation ID = e285a:54c48] in rule 'ct_requestiddemo' at function a!dynamicLink [line 406]: An error occurred while executing a save: Expression evaluation error at function 'type!{urn:com:appian:types:CT}CT_Comments_ID' [line 411]: Invalid index: Cannot index property 'requestId' of type Text into null value of type CT_Comments_ID?list

  • It should work. Can you please share the latest code ?

  • 0
    Certified Associate Developer
    in reply to Sanchit Gupta (Xebia)

    We can achieve it by without passing the parameters into the cdt.. Need to configure output of Script task of Process Model.

    The code here it works me in interface is: 

    addRowlink: a!dynamicLink(
              label: "Add new comment",
              saveInto: {
                a!save(
                  ri!mention,
                  append(
                    ri!mention,
                    'type!{urn:com:appian:types:CT}CT_Comments_ID'()
                    
                    /* rule input, type!cdt Name */
                  )
                )
              }
            )

  • If you are writing to the request table after form submission then update the value in requestId of Comment Cdt with the generated primary key of Request table.

    This is exactly what I meant when I said this. 

Reply Children
No Data