Sunday, 17 March 2019

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);
});
}

Add SPList using pnp Sharepoint framework



private AddSPList():void
{
pnp.sp.web.lists.add("Test","Test lists").then(function(response){
console.log("SPList added successfully !");
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});;
}

Break Permission on ListItem using pnp




private BreakInheritPermissionListItem():void
{
pnp.sp.web.lists.getByTitle("Employee").items.getById(9)
.breakRoleInheritance(true).then(function(response)
{
console.log("Item Permission breaked successfully");
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});
}

Lists spfx breakRoleInheritance using pnp



private BreakInheritPermissionOnSPList():void
{
pnp.sp.web.lists.getByTitle("Employee").breakRoleInheritance(true)
.then(function(response)
{
console.log("Permission breaked successfully");
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});
}

SiteGroups using pnp



private GetSPSiteGroup():void
{

pnp.sp.web.siteGroups.get().then(function(response)
{
console.log(response);
for(let index:number=0;index<response.length;index++)
{
console.log("Title :"+response[index].Title);
}
}).catch(function(exception)
{
alert("Something went wrong :"+exception);
});
}

spfx Siteusers using pnp



private GetSiteUsers():void
{
pnp.sp.web.siteUsers.get().then(function(response){

console.log(response);
for(let index:number=0;index<response.length;index++)
{
console.log("Title :"+response[index].Title+
" LoginName:"+response[index].LoginName+" Email:"+response[index].Email);
}


}).catch(function(exception){

alert("Something went wrong :"+exception);
})

}