SOLVED

How do I format a SharePoint list column input to complete a URL?

Copper Contributor

Hello I am relatively new to SharePoint and JSON code.  I am trying to design a list column so that when a user types in the entry the entry is then automatically converted into a URL.  For example, the input is ProjectName and the final column output is https://company.sharepoint.com/sites/ParentSite/ProjectName. 

 

Is this:

a) possible?

b) if possible how would I go about being able to do this?

c) can I further format the output to show just the ProjectName but formatted as a hyperlink?

 

Thank you in advance!

5 Replies
best response confirmed by RogueWolf1985 (Copper Contributor)
Solution

@RogueWolf1985 Yes, this is possible. You can use below JSON code on your ProjectName column:

 

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "a",
    "txtContent": "@currentField",
    "attributes": {
        "target": "_blank",
        "href": "='https://company.sharepoint.com/sites/ParentSite/' + @currentField"
    }
}

 

 

Also, if "https://company.sharepoint.com/sites/ParentSite" is the same site where you are adding this JSON code then you can also use "@currentWeb" instead of hard coding the site URL in JSON like below:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "a",
"txtContent": "@currentField",
"attributes": {
"target": "_blank",
"href": "=@currentWeb + '/' + @currentField"
}
}

Use column formatting to customize SharePoint 


Please click Mark as Best Response if my post helped you solve your issue. This will help others find the correct solution easily. It also closes the item. If the content was useful in other ways, please consider giving it Like.

Perfect! Thank you so much!
Thank you for the reference! This will be helpful in the future.
Great, glad it worked for you.
1 best response

Accepted Solutions
best response confirmed by RogueWolf1985 (Copper Contributor)
Solution

@RogueWolf1985 Yes, this is possible. You can use below JSON code on your ProjectName column:

 

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "a",
    "txtContent": "@currentField",
    "attributes": {
        "target": "_blank",
        "href": "='https://company.sharepoint.com/sites/ParentSite/' + @currentField"
    }
}

 

 

Also, if "https://company.sharepoint.com/sites/ParentSite" is the same site where you are adding this JSON code then you can also use "@currentWeb" instead of hard coding the site URL in JSON like below:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "a",
"txtContent": "@currentField",
"attributes": {
"target": "_blank",
"href": "=@currentWeb + '/' + @currentField"
}
}

Use column formatting to customize SharePoint 


Please click Mark as Best Response if my post helped you solve your issue. This will help others find the correct solution easily. It also closes the item. If the content was useful in other ways, please consider giving it Like.

View solution in original post