I have enabled content approval for a custom list. And I have a html page where the requirement is to show all the approved items in the list using SPServices. With content approval enabled, users with Read/Edit permission(except the author of list item) are able to see only the approved content. But the users with other Higher permission level are able to see the non-approved content as well. Is there any solution available to show only approved content to all users?
2 Answers
There are a couple of options if you want to manage it within the list.
- Edit view and Go to -> 'Filter' -> Select 'Approval Status' column and enter 'Approved'(language sensitive).
If you want to manipulate via any code using this CAML filter to get specific items.
<Eq> <FieldRef Name='_ModerationStatus' /> <Value Type='ModStat'>'Approved'</Value> </Eq>
Note: ModerationStatus value is language sensitive remember to translate and use correct word.
Update
C#:
foreach(SPListItem item in items)
{
foreach(var itmversion in item.Versions)
{
if(itmversion.Level == "Published")
{...}
}
}
Powershell:
foreach($item in $ListItems)
{
foreach($version in $item.Versions | ? { ($_.Level -eq "Published") })
{...}
}
-
both the option will filter data based on the current approval status. My requirement is to fetch the last approved version of a list item even if it is currently under pending approval status.– ObilirajCommented Jan 2, 2018 at 6:50
-
You can do as suggested, create new view filter with 'Approval Status' is equal to 'Approved':
But Why are you want to achieve that?
By default, if you choose "Only users who can approve items (and the author of the item)", with content approval enabled:
1.users with Read/Edit permission(except the author of list item) are able to see the last approved version of a List Item.
2.users (the author of list item) or with other Higher permission level are able to see the non-approved content.
If you configure that only show last Major versions for all users in SharePoint, that is to say no one can approve the document?