0

I have enabled ratings on my list in sharepoint online using PnP script and the rating is now visible in the list but the ratings are not visible on the "View Item" form. I have used following code to enable rating on the List.

$Context = Get-PnPContext
$AverageRatingField = $Web.Fields.GetById([guid]"5a14d1ab-1513-48c7-97b3-657a5ba6c742") # AverageRating
    $RatingCountField = $Web.Fields.GetById([guid]"b1996002-9167-45e5-a4df-b2c41c6723c7") # RatingCount
    $RatedByField = $Web.Fields.GetById([guid]"4D64B067-08C3-43DC-A87B-8B8E01673313") # RatedBy
    $RatingsField = $Web.Fields.GetById([guid]"434F51FB-FFD2-4A0E-A03B-CA3131AC67BA") # Ratings
    $LikesCountField = $Web.Fields.GetById([guid]"6E4D832B-F610-41a8-B3E0-239608EFDA41") # LikesCount
    $LikedByField = $Web.Fields.GetById([guid]"2CDCD5EB-846D-4f4d-9AAF-73E8E73C7312") # LikedBy
    $Context.Load($AverageRatingField)
    $Context.Load($RatingCountField)
    $Context.Load($RatedByField)
    $Context.Load($RatingsField)
    $Context.Load($LikesCountField)
    $Context.Load($LikedByField)
    $Context.ExecuteQuery()
    # Get the library for the site
    $ServerRelativeUrl = $Web.ServerRelativeUrl
    if ($ServerRelativeUrl -ne "/")
    {
        $ServerRelativeUrl = $ServerRelativeUrl + "/"
    }
    $List = Get-PnPList -Identity "MyList"
    $ListRootFolder = $List.RootFolder
    $ListRootFolderProperties = $ListRootFolder.Properties
    $Context.Load($List)
    $Context.Load($ListRootFolder)
    $Context.Load($ListRootFolderProperties)
    $Context.ExecuteQuery()

    $List.Fields.Add($AverageRatingField)
    $List.Fields.Add($RatingCountField)
    $List.Fields.Add($RatedByField)
    $List.Fields.Add($RatingsField)
    $List.Fields.Add($LikesCountField)
    $List.Fields.Add($LikedByField)
    $List.Update()
    $Context.ExecuteQuery()
    # Update default view
    $ListDefaltView = $List.DefaultView
    $Context.Load($ListDefaltView)
    $Context.ExecuteQuery()
    $ListDefaltView.ViewFields.Add("Rating (0-5)")
    $ListDefaltView.Update()
    $Context.ExecuteQuery()
    $ListRootFolderProperties["Ratings_x005f_VotingExperience"] = "Ratings"
    $ListRootFolderProperties["Ratings_VotingExperience"] = "Ratings" 
    $ListRootFolder.Update()
    $Context.ExecuteQuery()
0

I got the fix for this.

$AverageRatingField.SetShowInDisplayForm($true)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.