2

I know I can get current's web properties like this, Grab a specific property bag using ECMA script

But I have this,

  • ParentWebUrl:

  • PropertyName:

What I want is all child web's URL and property X, but I am not even sure if this is possible?

This is what I am trying,

   var context = new SP.ClientContext('https://myportal.erer.com/sdsd');
   var web = context.get_web(); 
   var subWebs = web.get_webs();

   context.load(subWebs, 'Include(Title, PropertyX)');
   context.executeQueryAsync(
    function () {  
         for (var i = 0; i < subWebs.get_count(); i++) {
            var subWeb = subWebs.itemAt(i);
            var parentWeb = subWeb.get_parentWeb();  //parent web ==  root web
            console.log(subWeb.get_title());
          }
    },
    function (sender, args) {
       console.log(args.get_message());
    }
   );

How to include custom property X to it ? if I try above.. I get this error,

Field or property "PropertyX" does not exist.


I somehow able to make it work but it's getting allproperties when it should only get what I want, any idea ?

    var ctx = new SP.ClientContext('https://example...');
    var webs = ctx.get_web().get_webs();
    var websProps = {};
    ctx.load(webs,'Include(Url,AllProperties)');
    ctx.executeQueryAsync(function(){
            var e = webs.getEnumerator();
            while (e.moveNext()) {
                var web = e.get_current();
                var webUrl = web.get_url();
                var props = web.get_allProperties();
                var propNameValues = props.get_fieldValues();
                websProps[webUrl] = {'PropertyX': propNameValues['propertyx']};
            }
            console.log(JSON.stringify(websProps)); 
        },
        function(sender, args){
            //Handle error
        }
    );

I get undefined if I change above to following,

ctx.load(webs,'Include(Url,propertyx)');
Mohamed El-Qassas MVP
  • 45,382
  • 9
  • 53
  • 96
Mathematics
  • 1,753
  • 5
  • 28
  • 56

0 Answers0