1

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.

2 Answers 2

0

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);
    }
})
1
  • Excelent, thanks so much!!! I try in this way and I can get the values.
    – fsilisque
    Dec 19, 2019 at 13:05
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.