2

as we know, there are draft item security inside SharePoint (see the link) which would allow the item to stay at the draft status and it would prevent the content available to all users. I created a SharePoint hosted app with a document library. However I didn't see the library setting at the document library at app web at all even I am an administrator user on the parent host site, thus I am not able to enable such setting. Just wonder if anyone knows how I could enable the draft item security in this case then. Can I enable it programmatically?

  • The question makes almost zero sense and the provided link redirects to some survey spam site. If you want to manage the Draft visibility settings for a list, you can get and set the DraftVersionVisibility (enum) property. //0=Reader, 1=Author, 2=Approver – Panoone Aug 30 '16 at 4:39
5

You can set it with CSOM by setting the EnableModeration member to true:

using (var ctx = new ClientContext(url))
{
    var list = ctx.Web.Lists.GetByTitle('List Name');
    list.EnableModeration = true;

    // Optional, set approval workflow for content approval
    list.EnableMinorVersions = true;    // Below will throw error if this is not enabled
    list.DefaultContentApprovalWorkflowId = Guid.Parse ("00000000-0000-0000-0000-000000000000");

    ctx.ExecuteQuery();
}

If you're using JSOM:

var ctx = new SP.ClientContext(siteUrl);
var web = ctx.get_web();
var list = web.get_lists().getByTitle('Your list');

list.set_enableModeration(true);
list.set_enableMinorVersions(true);
list.set_defaultContentApprovalWorkflowId("guid");
ctx.executeQueryAsync(success, error);

If you use JSOM, you might want to double check my syntax, I might've messed it up.

0

while using JSOM, below thing works perfectly(there is some issue with wjervis code , but thanks for your hint): pass site title in button click and call the function.

var clientContext=null;
var web=null;
var oList = null;

function GetData(title)
{
    var url = 'some url' + title;
    clientContext=new SP.ClientContext(url);    
    web = clientContext.get_web();  
    oList = web.get_lists().getByTitle("list name");
    //important
    oList.set_draftVersionVisibility(0);
    oList.update(); 
    clientContext.load(oList);

    clientContext.executeQueryAsync(
    Function.createDelegate(this, this.onQuerySucceeded), 
    Function.createDelegate(this, this.onQueryFailed)
    );
 }
function onQuerySucceeded() {
        if(this.oList.get_draftVersionVisibility() < 1)
            alert('Versioning set successfully');
        else
            alert('Some issue , please check again');
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
}   

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.