SOLVED

Debugging SPFx App Customizer

%3CLINGO-SUB%20id%3D%22lingo-sub-77952%22%20slang%3D%22en-US%22%3EDebugging%20SPFx%20App%20Customizer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-77952%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20had%20great%20success%20debugging%20SPFx%20web%20parts%20using%20the%20Chrome%20extension.%20Is%20there%20a%20way%20to%20get%20this%20to%20work%20with%20the%20framework%20extensions%3F%20I'm%20trying%20to%20build%20an%20Application%20Customizer%20that%20builds%20a%20menu%20in%20the%20header%20based%20on%20the%20contents%20of%20a%20SP%20links%20list%20('OrangeLinks')%20and%20having%20a%20heck%20of%20time%20figuring%20out%20why%20I%20can't%20get%20it%20to%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20idea%20is%20pretty%20simple%3A%20in%20the%20onRender()%20event%20I%20am%20assigning%20some%20html%20to%20the%20_headerPlaceholder.domElement.innerHTML%2C%20then%20calling%20a%20method%20to%20get%20the%20links%20out%20of%20the%20list%20which%20in%20turn%20calls%20a%20method%20to%20use%20the%20returned%20data%20to%20construct%20the%20html%20for%20the%20header.%20When%20all%20the%20data%20has%20been%20turned%20into%20HTML%20links%2C%20I%20am%20assigning%20that%20to%20the%20%3C%2FP%3E%3CDIV%3E%20that%20has%20already%20been%20put%20in%20the%20_headerPlaceholder.%20Here's%20the%20code%3A%3CP%3E%3C%2FP%3E%3CPRE%3E%20%20public%20onRender()%3A%20void%20%7B%0A%20%20%20%20if%20(!this._headerPlaceholder)%20%7B%0A%20%20%20%20%20%20this._headerPlaceholder%20%3D%20this.context.placeholders.tryAttach(%0A%20%20%20%20%20%20%20%20'PageHeader'%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20onDispose%3A%20this._onDispose%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%0A%20%20%20%20%20%20%2F%2F%20The%20extension%20should%20not%20assume%20that%20the%20expected%20placeholder%20is%20available.%0A%20%20%20%20%20%20if%20(!this._headerPlaceholder)%20%7B%0A%20%20%20%20%20%20%20%20console.error('The%20expected%20placeholder%20was%20not%20found.')%3B%0A%20%20%20%20%20%20%20%20return%3B%0A%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20if%20(this.properties)%20%7B%0A%20%20%20%20%20%20%20%20let%20headerString%3A%20string%20%3D%20this.properties.Header%3B%0A%20%20%20%20%20%20%20%20if%20(!headerString)%20%7B%0A%20%20%20%20%20%20%20%20%20%20headerString%20%3D%20'(Header%20property%20was%20not%20defined.)'%3B%0A%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20if%20(this._headerPlaceholder.domElement)%20%7B%0A%20%20%20%20%20%20%20%20%20this._headerPlaceholder.domElement.innerHTML%20%3D%20%60%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26lt%3Bdiv%20class%3D%22%24%7Bstyles.app%7D%22%26gt%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26lt%3Bdiv%20class%3D%22ms-bgColor-orange%20ms-fontColor-white%20%24%7Bstyles.header%7D%22%26gt%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26lt%3Bdiv%20id%3D%22orangeLinks%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26lt%3B%2Fdiv%26gt%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26lt%3B%2Fdiv%26gt%3B%60%3B%0A%0A%20%20%20%20%20%20%7D%20%0A%20%20%20%20%20%20this.getOrangeLinks()%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%0A%20private%20getOrangeLinks()%3A%20void%20%7B%0A%20%20%20%20pnp.sp.web.lists.getByTitle('OrangeLinks').items.select('URL').get().then((links%3A%20any)%20%3D%26gt%3B%20%7B%0A%20%20%20%20%20%20this.buildOrangeLinks(links)%3B%0A%20%20%20%20%7D)%3B%0A%20%20%7D%0A%0A%20%20private%20buildOrangeLinks(links%3A%20any)%3A%20void%20%7B%0A%20%20%20%20let%20linkList%3A%20string%20%3D%20%60%60%3B%0A%20%20%20%20for%20(let%20i%3A%20number%20%3D%200%3B%20i%20%26lt%3B%20links.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20%20%20%2F%2F---%20if%20there%20are%20already%20some%20links%2C%20add%20spaces%20before%20this%20one%0A%20%20%20%20%20%20if%20(i%20%26gt%3B%200)%20%7B%0A%20%20%20%20%20%20%20%20linkList%20%2B%3D%20%60%26amp%3Bnbsp%3B%26amp%3Bnbsp%3B%26amp%3Bnbsp%3B%7C%26amp%3Bnbsp%3B%26amp%3Bnbsp%3B%26amp%3Bnbsp%3B%60%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20let%20link%20%3D%20%60%26lt%3Ba%20href%3D%22%24%7Bescape(links%5Bi%5D.URL.Url)%7D%22%20target%3D%22_blank%22%26gt%3B%24%7Bescape(links%5Bi%5D.URL.Description)%7D%26lt%3B%2Fa%26gt%3B%60%3B%0A%20%20%20%20%20%20linkList%20%2B%3D%20link%3B%0A%20%20%20%20%7D%0A%20%20%20%20%24('%23orangeLinks').html(linkList)%3B%0A%20%20%20%20return%3B%0A%20%20%7D%3C%2FPRE%3E%3CP%3EAll%20I%20get%20is%20blank%20header.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15869i21D8FB81A6EE2790%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SPFxExt-App-Empty-Header.JPG%22%20title%3D%22SPFxExt-App-Empty-Header.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EEmpty%20Header%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EFunny%20enough%2C%20this%20scenario%20(render()-%26gt%3Bpnp%20data%20function-%26gt%3Bhtml%20building%20function%20%26amp%3B%20assignment%20by%20jQuery)%20works%20just%20fine%20in%20a%20SPFx%20web%20part%2C%20so%20something%20about%20the%20scope%20or%20timing%20of%20execution%20must%20be%20different.%20%26nbsp%3BAny%20thoughts%20would%20be%20most%20welcome.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78951%22%20slang%3D%22en-US%22%3ERe%3A%20Debugging%20SPFx%20App%20Customizer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78951%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F2387%22%20target%3D%22_blank%22%3E%40Pieter%20Veenstra%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EApparently%20there%20are%20some%20additional%20instuctions%20required%20for%20the%20PnP%20JS%20and%20SPFx%20to%20play%20nicely%20with%20one%20another.%20%26nbsp%3BThanks%20to%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F24453%22%20target%3D%22_blank%22%3E%40Patrick%20Rodgers%3C%2FA%3E%26nbsp%3Bfor%20pointing%20me%20to%20the%20missing%20key%20described%20in%26nbsp%3B%3CA%20title%3D%22Using%20sp%20pnp%20js%20in%20SharePoint%20Framework%20-%20Establish%20Context%22%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-JS-Core%2Fwiki%2FUsing-sp-pnp-js-in-SharePoint-Framework%23establish-context%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EUsing%20sp%20pnp%20js%20in%20SharePoint%20Framework%20-%20Establish%20Context%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20single%20call%20in%20the%20onInit()%20method%20override%20does%20the%20trick%3A%3C%2FP%3E%3CPRE%3E%40override%0A%20%20public%20onInit()%3A%20Promise%26lt%3Bvoid%26gt%3B%20%7B%0A%20%20%20%20return%20super.onInit().then(_%20%3D%26gt%3B%20%7B%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20%2F%2F---%20ensure%20that%20the%20current%20web%20is%20used%20for%20all%20pnp%20calls%0A%20%20%20%20%20%20pnp.setup(%7B%0A%20%20%20%20%20%20%20%20spfxContext%3A%20this.context%0A%20%20%20%20%20%20%7D)%3B%0A%0A%20%20%20%20%7D)%3B%0A%20%20%7D%3C%2FPRE%3E%3CP%3EThe%20REST%20call%20is%20now%20forming%20properly.%26nbsp%3BIt%20sure%20would%20be%20nice%20to%20have%20complete%2C%20organized%20documentation%20all%20together%20in%20ONE%20PLACE.%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20again%20for%20your%20interest%20and%20assistance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78584%22%20slang%3D%22en-US%22%3ERe%3A%20Debugging%20SPFx%20App%20Customizer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78584%22%20slang%3D%22en-US%22%3E%3CP%3ERan%20%22npm%20ls%22%20and%20this%20was%20the%20result%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20299px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F16007iCFCDAF8C04AA7706%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22npm-ls.JPG%22%20title%3D%22npm-ls.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3Enpm%20ls%20output%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EShould%20be%20the%20latest%20because%20I%20only%20built%20this%20project%20this%20week!%20%3B)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78401%22%20slang%3D%22en-US%22%3ERe%3A%20Debugging%20SPFx%20App%20Customizer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78401%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20looks%20indeed%20that%20the%20REST%20Url%20isn't%20correct.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20my%20code%20I%20tried%20this%3A%3C%2FP%3E%3CPRE%3Epnp.sp.web.lists.getByTitle('MyList').items.get().then((items%3A%20any)%20%3D%26gt%3B%20%7B%20%0A%26nbsp%3B%20%26nbsp%3B%20return%20items%3B%0A%7D)%3B%3C%2FPRE%3E%3CP%3Eand%20the%20above%20worked%20as%20expected%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20below%20call%20roughly%20does%20the%20same%20thing%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3Ereturn%20this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl%20%2B%20%60%2F_api%2Fweb%2Flists%2FGetByTitle('MyList')%2Fitems%60%2C%20SPHttpClient.configurations.v1)%0A.then((response%3A%20SPHttpClientResponse)%20%3D%26gt%3B%20%7B%0Areturn%20response.json()%3B%0A%7D)%3B%3C%2FPRE%3E%3CP%3ECan%20you%20double%20check%20that%20you%20have%20the%20latest%20version%20of%20the%20pnp%20modules%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can't%20see%20much%20of%20a%20difference%20between%20your%20code%20and%20my%20code.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78352%22%20slang%3D%22en-US%22%3ERe%3A%20Debugging%20SPFx%20App%20Customizer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78352%22%20slang%3D%22en-US%22%3E%3CP%3E%26gt%3B%26gt%3B%3CSPAN%3ECan%20you%20try%20without%20the%20select.%20You%20should%20get%20all%20items%20coming%20back.%20%3C%2FSPAN%3E%26lt%3B%26lt%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20select%20is%20not%20the%20problem%2C%20it's%20not%20filtering%20any%20rows%2C%20only%20ensuring%20that%20I%20am%20only%20bringing%20back%20the%20one%20column%20I%20am%20actually%20interested%20in.%20%26nbsp%3BIf%20you%20look%20at%20the%20ATOM%20formatted%20results%20above%2C%20you'll%20see%20that%20I%20am%20returning%203%20items%2C%20but%20only%20the%20URL%20field%20for%20each%20item.%20%26nbsp%3BThere%20are%20only%203%20items%20in%20the%20list.%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20I%20do%20as%20you%20suggest%20by%20removing%20the%20select%2C%20I%20am%20still%20seeing%20the%20incorrectly%20formed%20REST%20call%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20811px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15962i5E5C941CE9A42FB6%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SPFxExt-PnPCall4.JPG%22%20title%3D%22SPFxExt-PnPCall4.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ERevised%20PnP%20call%2C%20per%20your%20suggestion%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15963i37D533945932C64C%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SPFxExt-PnPCall5.JPG%22%20title%3D%22SPFxExt-PnPCall5.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EREST%20call%20still%20messed%20up%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EI%20still%20only%20get%20back%20the%20same%203%20items%2C%20I%20just%20get%20a%20whole%20lot%20more%20fields%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15964i87DF8DD6E2BB780B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SPFxExt-PnPCall6.JPG%22%20title%3D%22SPFxExt-PnPCall6.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EMUCH%20more%20data...%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3ESo%2C%20no%2C%20the%20select%20is%20not%20the%20issue...still%20trying%20figure%20out%20why%20the%20PnP.js%20is%20malforming%20the%20REST%20call...%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78302%22%20slang%3D%22en-US%22%3ERe%3A%20Debugging%20SPFx%20App%20Customizer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78302%22%20slang%3D%22en-US%22%3ECan%20you%20try%20without%20the%20select.%20You%20should%20get%20all%20items%20coming%20back.%20If%20mot%20then%20your%20list%20and%20is%20incorrect.%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78235%22%20slang%3D%22en-US%22%3ERe%3A%20Debugging%20SPFx%20App%20Customizer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78235%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F2387%22%20target%3D%22_blank%22%3E%40Pieter%20Veenstra%3C%2FA%3E%2C%20Thanks%20for%20the%20reply.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20does%20indeed%20seem%20that%20no%20links%20are%20being%20returned%20but%20it%20turns%20out%20not%20to%20be%20what%20I%20thought.%20I%20added%20the%20console%20log%20call%20as%20you%20suggested%20like%20so%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20747px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15922iF0A0C14E8C8D1B90%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SPFxExt-PnPCall1.JPG%22%20title%3D%22SPFxExt-PnPCall1.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EPnP%20Call%20in%20my%20code%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EBut%20when%20I%20went%20to%20the%20console%20tab%20of%20the%20inspector%20window%20in%20my%20browser%2C%20I%20noticed%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20992px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15923i17EBEB1D27505B0A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SPFxExt-PnPCall2.JPG%22%20title%3D%22SPFxExt-PnPCall2.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EIncorrect%20REST%20Call%20generated%20by%20PnP%3C%2FSPAN%3E%3C%2FSPAN%3EFor%20some%20reason%20it%20seems%20that%20the%20translation%20from%20the%20PnP%20call%20to%20the%20REST%26nbsp%3Bcall%20is%20adding%20the%20SitePages%20folder%20to%20the%20path%3B%20it's%20now%20obvious%20why%20the%20call%20is%20not%20returning%20any%20items!%20If%20I%20remove%20the%20offending%20folder%20from%20the%20path%20and%20just%20plug%20the%20result%20into%20the%20address%20bar%20of%20the%20browser%2C%20you%20can%20see%20that%20I%20am%20returning%20the%20items%26nbsp%3Bexpected%20(in%20the%20default%20atom%20format%2C%20but%20it%20proves%20that%20the%20list%20is%20there%20and%20will%20return%20rows%20if%20the%20call%20is%20properly%20constructed)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15924iE2D2930FCD7EDC8A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SPFxExt-PnPCall3.JPG%22%20title%3D%22SPFxExt-PnPCall3.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EData%20Returned%20when%20REST%20call%20path%20is%20fixed%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3ESo%20my%20question%20now%20is%3A%20why%20is%20the%20PnP.js%20not%20making%20the%20correct%20REST%20call%3F%20%26nbsp%3BHave%20I%20missed%20a%20step%20somewhere%3F%20Am%20I%20making%20a%20faulty%20assumption%20that%20%3CSTRONG%3Epnp.sp.web%3C%2FSTRONG%3Erepresents%20the%20context%20of%20the%20current%20default%20web%20site%3F%20Or%20is%20it%20something%20else%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20input%2C%20btw.%20%26nbsp%3BI've%20been%20doing%20traditional%20SP%20Development%20for%2010%20years%20and%20am%20still%20climbing%20the%20learning%20curve%20on%20the%20new%20%22remote%22%20platform.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78123%22%20slang%3D%22en-US%22%3ERe%3A%20Debugging%20SPFx%20App%20Customizer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78123%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F35575%22%20target%3D%22_blank%22%3E%40Joseph%20Ackerman%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20suspect%20that%26nbsp%3B%3C%2FP%3E%3CPRE%3Epnp.sp.web.lists.getByTitle('OrangeLinks').items.select('URL').get().then((links%3A%20any)%20%3D%26gt%3B%20%7B%3CBR%20%2F%3E%20%20%20...%0A%7D%3C%2FPRE%3E%3CP%3Eisn't%20returning%20any%20links.%3C%2FP%3E%3CP%3ECan%20you%20add%20console.log(%22started%22)%20%26nbsp%3Bat%20the%20beginning%20of%20the%20getOrangeLinks%20method%20to%20make%20sure%20that%20the%20method%20is%20called%20at%20all.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethen%20can%20you%20add%20a%20console.log(links)%20to%20make%20sure%20that%20we%20get%20any%20results%20returned%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

I have had great success debugging SPFx web parts using the Chrome extension. Is there a way to get this to work with the framework extensions? I'm trying to build an Application Customizer that builds a menu in the header based on the contents of a SP links list ('OrangeLinks') and having a heck of time figuring out why I can't get it to work.

 

The idea is pretty simple: in the onRender() event I am assigning some html to the _headerPlaceholder.domElement.innerHTML, then calling a method to get the links out of the list which in turn calls a method to use the returned data to construct the html for the header. When all the data has been turned into HTML links, I am assigning that to the <div> that has already been put in the _headerPlaceholder. Here's the code:

  public onRender(): void {
    if (!this._headerPlaceholder) {
      this._headerPlaceholder = this.context.placeholders.tryAttach(
        'PageHeader',
        {
          onDispose: this._onDispose
        });

      // The extension should not assume that the expected placeholder is available.
      if (!this._headerPlaceholder) {
        console.error('The expected placeholder was not found.');
        return;
      }

      if (this.properties) {
        let headerString: string = this.properties.Header;
        if (!headerString) {
          headerString = '(Header property was not defined.)';
      }

      if (this._headerPlaceholder.domElement) {
         this._headerPlaceholder.domElement.innerHTML = `
                 <div class="${styles.app}">
                   <div class="ms-bgColor-orange ms-fontColor-white ${styles.header}">
                     <div id="orangeLinks"></div>
                   </div>
                 </div>`;

      } 
      this.getOrangeLinks();
    }
  }

 private getOrangeLinks(): void {
    pnp.sp.web.lists.getByTitle('OrangeLinks').items.select('URL').get().then((links: any) => {
      this.buildOrangeLinks(links);
    });
  }

  private buildOrangeLinks(links: any): void {
    let linkList: string = ``;
    for (let i: number = 0; i < links.length; i++) {
      //--- if there are already some links, add spaces before this one
      if (i > 0) {
        linkList += `&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;`;
      }
      let link = `<a href="${escape(links[i].URL.Url)}" target="_blank">${escape(links[i].URL.Description)}</a>`;
      linkList += link;
    }
    $('#orangeLinks').html(linkList);
    return;
  }

All I get is blank header.

Empty HeaderEmpty Header

Funny enough, this scenario (render()->pnp data function->html building function & assignment by jQuery) works just fine in a SPFx web part, so something about the scope or timing of execution must be different.  Any thoughts would be most welcome.

 

7 Replies

Hi @Joseph Ackerman,

 

I suspect that 

pnp.sp.web.lists.getByTitle('OrangeLinks').items.select('URL').get().then((links: any) => {
... }

isn't returning any links.

Can you add console.log("started")  at the beginning of the getOrangeLinks method to make sure that the method is called at all.

 

then can you add a console.log(links) to make sure that we get any results returned?

 

 

 

Highlighted

Hello @Pieter Veenstra, Thanks for the reply.

 

It does indeed seem that no links are being returned but it turns out not to be what I thought. I added the console log call as you suggested like so:

 

PnP Call in my codePnP Call in my code

But when I went to the console tab of the inspector window in my browser, I noticed this:

 

Incorrect REST Call generated by PnPIncorrect REST Call generated by PnPFor some reason it seems that the translation from the PnP call to the REST call is adding the SitePages folder to the path; it's now obvious why the call is not returning any items! If I remove the offending folder from the path and just plug the result into the address bar of the browser, you can see that I am returning the items expected (in the default atom format, but it proves that the list is there and will return rows if the call is properly constructed):

 

Data Returned when REST call path is fixedData Returned when REST call path is fixed

So my question now is: why is the PnP.js not making the correct REST call?  Have I missed a step somewhere? Am I making a faulty assumption that pnp.sp.web represents the context of the current default web site? Or is it something else?

 

Thanks for your input, btw.  I've been doing traditional SP Development for 10 years and am still climbing the learning curve on the new "remote" platform.

Highlighted
Can you try without the select. You should get all items coming back. If mot then your list and is incorrect.
Highlighted

>>Can you try without the select. You should get all items coming back. <<

 

The select is not the problem, it's not filtering any rows, only ensuring that I am only bringing back the one column I am actually interested in.  If you look at the ATOM formatted results above, you'll see that I am returning 3 items, but only the URL field for each item.  There are only 3 items in the list.  

 

When I do as you suggest by removing the select, I am still seeing the incorrectly formed REST call:

 

Revised PnP call, per your suggestionRevised PnP call, per your suggestion

REST call still messed upREST call still messed up

I still only get back the same 3 items, I just get a whole lot more fields:

 

MUCH more data...MUCH more data...

So, no, the select is not the issue...still trying figure out why the PnP.js is malforming the REST call...

Highlighted

It looks indeed that the REST Url isn't correct.

 

In my code I tried this:

pnp.sp.web.lists.getByTitle('MyList').items.get().then((items: any) => { 
    return items;
});

and the above worked as expected

 

The below call roughly does the same thing:

 

return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/web/lists/GetByTitle('MyList')/items`, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
return response.json();
});

Can you double check that you have the latest version of the pnp modules?

 

I can't see much of a difference between your code and my code.

 

Highlighted

Ran "npm ls" and this was the result:

 

npm ls outputnpm ls output

Should be the latest because I only built this project this week! ;)

Highlighted
Best Response confirmed by Joseph Ackerman (Contributor)
Solution

@Pieter Veenstra,

 

Apparently there are some additional instuctions required for the PnP JS and SPFx to play nicely with one another.  Thanks to @Patrick Rodgers for pointing me to the missing key described in Using sp pnp js in SharePoint Framework - Establish Context.

 

A single call in the onInit() method override does the trick:

@override
  public onInit(): Promise<void> {
    return super.onInit().then(_ => {
      
      //--- ensure that the current web is used for all pnp calls
      pnp.setup({
        spfxContext: this.context
      });

    });
  }

The REST call is now forming properly. It sure would be nice to have complete, organized documentation all together in ONE PLACE. :)

 

Thanks again for your interest and assistance.