Sunday, 17 March 2019

Batch Operation using pnp


private BatcOperation():void
{
let batchResults = [];
let batch=pnp.sp.createBatch();
pnp.sp.web.lists.getByTitle("Test").items.inBatch(batch).add({Title:"1"})
.then(function(response){
console.log(1);
batchResults.push(response);
});
pnp.sp.web.lists.getByTitle("Test").items.inBatch(batch).add({Title:"2"})
.then(function(response){
console.log(2);
batchResults.push(response);
});;
pnp.sp.web.lists.getByTitle("Test").items.inBatch(batch).add({Title:"3"})
.then(function(response){
console.log(3);
batchResults.push(response);
});;
pnp.sp.web.lists.getByTitle("Test").items.inBatch(batch).add({Title:"4"})
.then(function(response){
console.log(4);
batchResults.push(response);
});;
batch.execute().then(function(){
console.log("Final");
console.log(batchResults);
}).catch(function(exception){
alert("Something went wrong :"+exception);
});

}

spfx Get Files and Folder using pnp



private GetFilesFolder():void
{
pnp.sp.web.lists.getByTitle("Site Assets").items.getAll().then(function(response)
{
console.log(response);

}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});
}

spfx pnp delete folder


private DeleteFolder():void
{
//id of content type
pnp.sp.web.getFolderByServerRelativePath("SiteAssets/NewFolder").delete()
.then(function(response)
{
console.log("Folder Deleted !");
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});
}

spfx pnp add folder



private AddNewFolder():void
{
//id of content type
pnp.sp.web.folders.add("SiteAssets/NewFolder").then(function(response)
{
console.log("New Folder added !");
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});
}

spfx Add Content type to List/Library using pnp


private AddSiteToContentTypeToList():void
{
//id of content type
pnp.sp.web.lists.getByTitle("Test").contentTypes
.add("0x01002189FE08454A7F4ABA16A6F0D0E030FE","CustomContentType")
.then(function(response)
{
console.log("Content Type added to List!");
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});
}

spfx pnp create site content type



private CreateContentType():void
{
pnp.sp.site.rootWeb.contentTypes.add("CustomContentType","CustomContentType")
.then(function(response){
console.log("New Content Type created!");
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});
}

Add Site Columns using pnp



private AddSiteColumn():void
{
pnp.sp.site.rootWeb.fields.addText("DepartmentName").then(function(response){
console.log("New Site Column Added!");
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});
}

spfx delete list column using pnp

private DeleteSPListColumn():void
{

pnp.sp.web.lists.getByTitle("Test").fields.getByTitle("EmployeeName")
.delete().then(function(response){
console.log("Column Deleted!");
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});

}

Add List Column using pnp


private AddSPListColumn():void
{

pnp.sp.web.lists.getByTitle("Test").fields.addText("EmployeeName")
.then(function(response){
console.log("New Column added!");
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});

}

Delete SPList using pnp



private DeleteSPList():void
{
pnp.sp.web.lists.getByTitle("Employee").delete().then(function(response)
{
console.log("SharePoint List Deleted");
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});
}