Skip to main content
mollyn6512
August 23, 2022
Solved

Add record link to each part of a text string

  • August 23, 2022
  • 12 replies
  • 6 views

Hi Appian Community,

I have added into my interface a grid as shown below, which was called from a record type. 

ID     relateTo Column 3 Column 4
001 003/004
002 007/004/005
003 001/002/006
004
005
006
007

This is the code that I wrote for column 2 (relatedTo) but didn't work. I used split () to split each row into an array of text IDs, then trying to add link to each of that ID. 


a!richTextItem(
     text: split(fv!row[recordtype.relatedTo], "|"),
     link:  a!forEach(
              items: split(fv!row[recordtype.relatedTo], "|"),
              expression: a!recordLink(
                                       label: fv!item,
                                       recordType: recordType,
                                       identifier: fv!item,
                                       openLinkIn: "NEW_TAB"
        )

    )

)


I want to add link to each ID in column 2 (ID that related to ID in column 1), so when I click any in that text string, I can be directed to the record for that certain ID. I think the identifier needs to be specific but not sure how to do it.

Thanks for your help, and appologise if the code is confusing...

    Best answer by peter.lewis

    You're missing the a!richTextDisplayField() - you can't just put a!richTextItem() by itself, it must be contained within a Rich Text Display Field.

    Here's a working example if you want to check it out:

    a!localVariables(
      local!data: {
        a!map(id: 1, value: "1/2/3"),
        a!map(id: 2, value: "4/5/6")
      },
      a!gridField(
        data: local!data,
        columns: {
          a!gridColumn(
            label: "ID",
            value: fv!row.id
          ),
          a!gridColumn(
            label: "Value",
            value: a!richTextDisplayField(
              value: a!forEach(
                items: split(fv!row.value, "/"),
                expression: {
                  a!richTextItem(
                    text: fv!item,
                    link: a!recordLink(
                      recordType: 'recordType!{4c49fecf-28fc-447d-8acd-0547f4b609e6}PDL Case',
                      identifier: fv!item
                    ),
                    linkStyle: "STANDALONE"
                  ),
                  if(
                    fv!isLast,
                    "",
                    " / "
                  )
                }
              )
            )
          )
        }
      )
    )

    12 replies

    sunilnaikb0002
    August 23, 2022

    Hi,

    How about having the richTextItem in the loop?
    Let me make it more clear for you.

    you can have the richTextItem in the loop and add link to each text item you get out of the loop.

    Then the code would look this way.

    a!forEach(
      items: split(fv!row[recordtype.relatedTo], "|"),
      expression: a!richTextItem(
        text: fv!item,
        link: a!recordLink(
          label: fv!item,
          recordType: recordType,
          identifier: fv!item,
          openLinkIn: "NEW_TAB"
        )
      )
    )


    Please try it out!

    mollyn6512
    August 23, 2022

    Thanks for the guidance, It looks correct but somehow didn't work for me. I guess because I have the a!gridField outside of the code? I tried 2 ways but both failed...

    a!gridColumn(
          label: "Related To",
          value: a!forEach(
                                items: split(fv!row['recordType.Related To], "|"),
                                expression: if(
                                              IsBlank(fv!row['recordType.relatedTo]),
                                              "-",
                                              a!richTextItem(
                                                       text: fv!item,
                                                       link: a!recordLink(
                                                       label: fv!item,
                                                       recordType: recordType,
                                                       identifier: fv!item,
                                                       openLinkIn: "NEW_TAB"
                                                      )
                                                 )
                                            )                                     

                                     ),
          sortField: fv!row['recordType.Related To],
          align: "CENTER"
     ),

    Another way:

    a!gridColumn(
           label: "Related To",
           value: if(
                      IsBlank( fv!row['recordType.relatedTo]),
                      "-",
                      a!forEach(
                              items: split(fv!row[recordtype.relatedTo], "|"),
                              expression: a!richTextItem(
                                                           text: fv!item,
                                                           link: a!recordLink(
                                                                            label: fv!item,
                                                                            recordType: recordType,
                                                                            identifier: fv!item,
                                                                            openLinkIn: "NEW_TAB"
                                                                            )
                                                   )
                        ),
            sortField: recordType,
            align: "CENTER"
    ),

    sunilnaikb0002
    August 23, 2022

    Could you please share how the data is present in relatedTo column of your record type?