How get values that return sp.site.createModernTeamSite in pnpjs
-
08-02-2021 - |
Question
Using below function:
const s = await sp.site.createModernTeamSite(
CustomerName,
CustomerID,
true,
1033,
"Customer Site for " + CustomerName);
You can create a team Site, but how to get values from s
?
In the console, I can see GroupId
value. But from code, I am not able access to this.
Solution
createModernTeamSite returns Promise<void>
so you need get the value from callback function.
createModernTeamSite(displayName: string, alias: string, isPublic?: boolean, lcid?: number, description?: string, classification?: string, owners?: string[], hubSiteId?: string, siteDesignId?: string): Promise<void>;
sp.site.createModernTeamSite(
"LeeSPFxModernTeamA",
"LeeSPFxModernTeamA",
true,
1033,
"description")
.then((d:any) => {
if(d.d){
var groupId=d.d.CreateGroupEx.GroupId;
}else{
console.log(d);
}
})
OTHER TIPS
The createModernTeamSite
function is async
which returns Promise<void>
. So, you need to await
while it returns some value.
You can use your code like below:
import { sp } from "@pnp/sp";
sp.site.createModernTeamSite(
CustomerName,
CustomerID,
true,
1033,
"Customer Site for " + CustomerName)
.then(data => {
console.log(data);
});
When you will expand data
in console, you will see all the information returned by createModernTeamSite()
.
You can follow below documentation to see the properties you can pass to createModernTeamSite()
.
official documentation: Create a modern team site.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange