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.

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
scroll top