Skip to content
This repository has been archived by the owner. It is now read-only.

Issue with batching #279

Closed
russgove opened this issue Dec 22, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@russgove
Copy link
Contributor

commented Dec 22, 2016

Hi,
i have the following code in a webpart:

let batch: any = pnp.sp.createBatch();
  let securityInfo: SPSecurityInfo = new SPSecurityInfo();	
  pnp.sp.web.inBatch(batch).siteUsers.get().then((response) => {
    securityInfo.siteUsers = response.map((u) => {
      let user: SPSiteUser = new SPSiteUser();
      user.id = u.Id;
      user.name = u.Title;
      if (u.UserId) {
        user.userId = new SPExternalUser();
        user.userId.nameId = u.UserId.NameId;
        user.userId.nameIdIssuer = u.UserId.NameIdIssuer;
      }
      return user;
    });
  });
  pnp.sp.web.inBatch(batch).roleDefinitions.expand("BasePermissions").get().then((response) => {
    securityInfo.roleDefinitions = response.map((rd) => {
      const bp = new SPBasePermissions(rd.BasePermissions.High, rd.BasePermissions.Low);
      const roleDefinition: SPRoleDefinition = new SPRoleDefinition(
        parseInt(rd.Id),
        bp,
        rd.Description,
        rd.Hidden,
        rd.Name);
      return roleDefinition;
    });
  });
  
  return batch.execute().then(() => {
    return securityInfo;
  })

The line " return securityInfo;" is running before the individual hanlers are run.
I think all the nested calls shoul be resolved before the entire batch is resolved.

I am using build v1.0.6 .

@tavikukko

This comment has been minimized.

Copy link
Contributor

commented Dec 23, 2016

Try moving the inBatch just before the get() method.

pnp.sp.web.siteUsers.inBatch(batch).get().then((response) => {
pnp.sp.web.roleDefinitions.expand("BasePermissions").inBatch(batch).get().then((response) => {

@russgove russgove closed this Dec 23, 2016

@russgove

This comment has been minimized.

Copy link
Contributor Author

commented Dec 23, 2016

that works

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.