How to show comments according to user role?

A Score Level 1

Using a grid I display several rows of comments on a form. The requirement is that users should be able to see only their comments or final approval/rejection comments. They should not have visibility to the comments for the different approval flows. The current solution is showing every comment in a grid. Is there any way I can restrict the visibility of approval flow comments? Any recommendations? TIA

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    I hope you have a hierarchy of groups set up that generally define a user's role(s).  In this way it's pretty straightforward to use on-form logic to check whether the viewing user is in certain group(s).  Then you'd use additional on-form logic to simply decide whether different columns (or different comment types, presuming you have a systematic way to differentiate them) are shown for members of different groups.

  • 0
    A Score Level 1
    in reply to Mike Schmitt

    a!localVariables(
      local!commentsPageInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: 10,
        sort: a!sortInfo(field: "createddate", ascending: true)
      ),
      local!commentsData: todatasubset(
        arrayToPage: ri!savedComments,
        pagingConfiguration: local!commentsPageInfo
      ),
      a!sectionLayout(
        label: "Comments",
        
        contents: {
          a!gridField(
            emptyGridMessage: "No Comments Found",
            data: local!commentsData,
            pagingSaveInto: local!commentsPageInfo,
            columns: {
              a!gridColumn(
                label: "Comment",
                sortField: "text",
                value: fv!row.text,
                width: "WIDE"
              ),
              a!gridColumn(
                label: "User",
                sortField: "createdby",
                value: fv!row.createdby
              ),
              a!gridColumn(
                label: "Date Created",
                sortField: "createddate",
                value: fv!row.createddate
              )
            }
          ),
          a!paragraphField(
        label: " Add Comments",
            value: ri!initalComment,
            saveInto: {
              ri!initalComment,
              a!save(ri!userComment, loggedInUser())
            },
            
          )
        }
      )
    )

    This is how the code looks and is called in the main interface.

  • 0
    Certified Lead Developer
    in reply to Tan18

    Seems like you transport the comment in a process from one form to the other. In this case, you will need to implement a filter on your ri!savedComments. I would recommend using the filter() function in combination with a separate expression. Others might prefer to filter using foreach(). Both works, but this is what you need to do.

  • 0
    A Score Level 1
    in reply to Stefan Helzle

    I tried using foreach () function but it didn't work. Can you quote any example for the filter function?

  • 0
    Certified Lead Developer
    in reply to Tan18

    filter(
      rule!THIS_IS_YOUR_EXPRESSION(item:_),
      ri!savedComments
    )

    Your expression has a rule input called "item" and gets passed one item from the list. It then needs to implement your conditions and return true to keep that item in the list. The filter function will then iterate on the list and call your expression for each item.

  • 0
    Certified Lead Developer
    in reply to Tan18
    I tried using foreach ()

    Can you provide a bit more context?  What piece of the passed-in comment CDT are you trying to use to segregate what user(s) can see which comment(s)?