2

It maybe a SharePoint dummy level question for but I cannot find a way to do it.

In the Pages library we have enabled publishing feature. Only major version 1.0, 2.0, 3.0... are published and minor version are draft. I want to create a view to show all unpublished pages (and another view for all published pages). I can add a column shows version number only.

Can I accomplish it without programming?

4

Without code

On library click Create new view based on for ex. All items. Check columns you want to view and sort it how you like.

Under Filter

click Show items only when the following is true

Approval Status --- is greater than --- 0 << this is for all unpublished(Rejected, Pending, Draft)

Click OK

For Published view create one more view with

Approval Status --- is equal to --- 0 << this is for published(Approved)

And that's it

Reference

Display Name --- Approval Status

Internal Name --- _ModerationStatus

GUID --- {fdc3b2ed-5bf2-4835-a4bc-b885f3396a61}

Type --- ModStat


FYI

Status --- Internal Value

Approved --- 0

Rejected --- 1

Pending --- 2

Draft --- 3

Scheduled --- 4


EDIT

With code

unpublished-view

In the Code view just paste the following into your View’s XML inside the Query element:

<Where>
<Or>
    <Eq>
        <FieldRef Name="_ModerationStatus"/>
        <Value Type="ModStat">Draft</Value>
    </Eq>
    <IsNotNull>
        <FieldRef Name="CheckoutUser"/>
    </IsNotNull>
</Or>
</Where>

EDIT FINAL

If content Approval is disabled you can't see Approval status in edit view under filters so you must add it in code for that 2 new views (published.aspx and draft.aspx). Open SPDesigner and go to Pages/forms and edit that view. Find <Query> and paste that code after <Query>

For Draft view:

<Where>
<Or>
    <Eq>
        <FieldRef Name="_ModerationStatus"/>
        <Value Type="ModStat">Draft</Value>
    </Eq>
    <IsNotNull>
        <FieldRef Name="CheckoutUser"/>
    </IsNotNull>
</Or>
</Where>

For Publish view:

<Where>
<Or>
    <Eq>
        <FieldRef Name="_ModerationStatus"/>
        <Value Type="ModStat">Approved</Value>
    </Eq>
    <IsNotNull>
        <FieldRef Name="CheckoutUser"/>
    </IsNotNull>
</Or>
</Where>

*You can set 3 for Draft and 0 for Approved for _ModerationStatus value.

Save file and that's it. :)

  • I have not enabled content approval for Pages library. Will it still work? – Mark L Sep 25 '14 at 8:53
  • Try without. Library > Library Settings; Versioning Settings; Content Approval : Yes; Document Version History : Create major and minor (draft) versions; – Marko Tica Sep 25 '14 at 11:19
  • So I must enable content approval? – Mark L Sep 28 '14 at 1:31
  • You don't need to enable Content Approval. And then value for status Approved is 0 and for Draft status is 3. If you enable Content Approval then you have more statuses. Rejceted is 1, Pending is 2 and Scheduled is 4. – Marko Tica Sep 29 '14 at 7:48
  • If Content Approval is enabled you can edit view from UI and if Content Approval is disabled you must edit view through code (see EDIT FINAL in my answer) – Marko Tica Sep 29 '14 at 8:35

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.