Redirecting document citation URLs in Microsoft Copilot Studio Code Editor

Copper Contributor

Hi all, 

 

I've created a genAI boosted Copilot in Microsoft Copilot Studio, using uploaded documents as the sources. When I message the test Copilot in the console, the citation links just lead to a pop-up with the relevant section of text. Instead, I would like to redirect the citation URLs so they lead to the respective original document which is stored on SharePoint. For various reasons, I can't boost the Copilot with the Sharepoint page directly, hence saving it as a document and uploading. 

 

In the code editor, I have created a record that maps the name of the document to the url I want it to link to, like so:

 

    - kind: SetVariable
      id: setVariable_C9TaRa
      variable: Topic.source_mapping
      value: "{     \"doc1.docx\": \"https://sharepoint.com/sites/team/doc1.aspx\",     \"doc2.docx\": \"https://sharepoint.com/sites/team/doc2.aspx\"}"

    - kind: ParseValue
      id: OSXhWy
      variable: Topic.source_mapping_record
      valueType:
        kind: Record
        properties:
          doc1.docx: String
          doc2.docx: String

      value: =Topic.source_mapping

 

 

By default, the citation part of the code looks like this:

 

                    type: "Container",
                    items: ForAll(Topic.Answer.Text.CitationSources,
                      {
                        type: "TextBlock",
                        text: "[" & Id &"]: [" & Name & "]("& Url &")",
                        wrap: true,
                        size: "Small",
                        weight: "Lighter"
                      }
                    )

 

 

I changed the URL part (as the URL variable was empty as they're documents) so it instead calls my record with the source name to insert the URL. When I hard-code in the source name, it works perfectly and provides the link to the SharePoint, i.e, instead of having ("& Url &"), having:

 

("&Topic.source_mapping_record.'doc1.docx'&")

 

 

However, when I try to use the name variable instead of hard coding the name, like so:

 

("& "Topic.source_mapping_record." & "'"&Name&"'" &")

 

 It will just print (Topic.source_mapping_record.‘doc1.docx’) in the response citation. 

 

I basically need to know the correct syntax for embedding the variable 'Name' in the record call, so that it doesn't read the entire thing as a string. 

 

Thanks!

 

 

0 Replies