question

mziemba avatar image
0 Votes"
mziemba asked WendyLi-MSFT commented

Calculated columns with the site/channel title

Hi,
Is it possible to use a site title or channel name (if the site is created for the private channel in Teams) to set a column value in the SharePoint list?
I thought about calculated columns but it seems there is no refference to the site name.

office-sharepoint-onlinesharepoint-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

EmilyDu-MSFT avatar image
0 Votes"
EmilyDu-MSFT answered WendyLi-MSFT commented

@mziemba

Per my knowledge, calculated column does not support use site name as reference in it.

As a workaround, you could use following PowerShell to get site name then use site name to set column default value.

 $SiteURL = "https://tenant.sharepoint.com/sites/emilytest"
 $ListName = "list name"
 $ColumnName = "column name" #Internal Name
    
 Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
    
 $Web = Get-PnPWeb
 $DefaultValue = $Web.Title
     
 Set-PnPField -Identity $ColumnName -List $ListName -Values @{DefaultValue=$DefaultValue}

If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you @EmilyDu-MSFT for the PowerShell sample.
My goal was to set the field automatically whenever a new file is created in the documented library.
And the solution with PowerShell needs to be run from time to time as I guess, right?

0 Votes 0 ·

@mziemba

The above PowerShell is to set site name as a column default value. It means that when you upload each document into library, the column will show default value automatically.

Also, you could set default value for a column in the UI.

190810-image.png


1 Vote 1 ·
image.png (14.2 KiB)

@mziemba Do you have further questions about this issue? If you have any doubts, please feel free to reply.


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

0 Votes 0 ·

@mziemba

I’m checking how the things are going on about this issue. Whether the answer helps you?

If there is any problem with this issue, feel free to let me know.

0 Votes 0 ·