Pnpjs: Batch is not working with sitegroups

Created on 28 Sep 2018  路  6Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [ ] Bug
  • [ X ] Question
  • [ ] Documentation gap/issue

Hello. I am working with batch's and many times everything works without any problem but...

var batch = pnp.sp.createBatch();
userID = _spPageContextInfo.userId;

pnp.sp.web.siteGroups.getByName("XXXX").users.getById(userID).inBatch(batch).get().then(function (r) {
    console.log(r);
});

batch.execute().then(function () {
console.log("Done");
});

This is only a example I need to do more steps in batch ...but this step is not working...Please why...I am not sure if this is a bug or only my fault. Thank you

code answered question

All 6 comments

Hi @enti333,

Could you specify versions of SP and PnPjs?

I've just checked on SPO and PnPjs 1.2.1 and the same exactly request structure as you provided works for me:

image

Hello. Thank you very much for quick reply.
I am working with this files:
pnpjs.es5.umd.bundle.min.js
polyfill.min.js?callback=stuffisloaded&features=es6|always|gated,fetch|always|gated

pnpjs.es5.umd.bundle.min.js is version:
@pnp/pnpjs v1.1.4 - pnp - rollup library of core functionality (mimics sp-pnp-js)

Thank you very much,..

With PnPjs 1.1.4 and pnpjs.es5.umd.bundle.min.js loaded from CDN mentioned above code also works for me. So it's something else.

Hello. Again thank you for your help. I found what is a problem with this.
Please try to create group with name "Podate木艌a"... Then test your code with batch....
I Get this error:
Error making HttpClient request in queryable: [400] Bad Request ::> {"responseBody":{"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"sk-SK","value":"V媒raz web/sitegroups/getByName('Podate je neplatn媒."}}},"responseHeaders":{}}

But If I use code without batch it works...Hmm:)

So this code works:

  pnp.sp.web.siteGroups.getByName("Podate木艌a").users.getById(userID).get().then(function (r) {
        console.log(r);
    }).catch(function (err) {
    }); 

And this not:

    pnp.sp.web.siteGroups.getByName("Podate木艌a").users.getById(userID).inBatch(batch).get().then(function (r) {
        console.log(r);
    }).catch(function (err) {
        alert("");
    });  

Thank you

It can be related to the group name containing non-latin symbols. What if to try encodeURLComponent for the name before using it?

sp.web.siteGroups
  .getByName(encodeURIComponent('Podate木艌a'))
  .users.getById(userID)
  .inBatch(batch).get().then(console.log);

Will is change the picture?

Thank you very much it works great:) Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AJIXuMuK picture AJIXuMuK  路  3Comments

DennisGaida picture DennisGaida  路  3Comments

SpliceVW picture SpliceVW  路  3Comments

simonagren picture simonagren  路  3Comments

un-dres picture un-dres  路  3Comments