Hot answers tagged

5

You will need to do both the REST orderBy, and then use JavaScript to reverse the array of items in the returned results. The problem is thus: In order for the REST API to return only the n most recent items, you have to provide the ODATA orderBy the created date in Descending order. But, if you want to use or display those same n items in any other order ...


5

Using @pnp/sp framework, you can get the list of all site collections as below: Add the below import statement: import { sp, SearchQuery, SearchResults} from "@pnp/sp"; After that, you can get the data as below: sp.search({ Querytext: "contentclass:STS_Site", SelectProperties: ["Title", "SPSiteUrl", "WebTemplate&...


4

Do you want all sites in the tenant, or just the sites the user has permissions to? You can use the search API to return a list of webs or site collections the user has access to. https://yourServer/sites/yourSite/_api/search/query?querytext='contentclass:sts_web'&selectproperties='SiteId,Path,Title'&trimduplicates=true&rowlimit=1000 https://...


3

Internet Explorer does not implement some of the ECMAScipt 6 types used in PnP.js. Because of this you need to use a couple ployfill libraries that implement the missing types. There are a few options on which polyfill libraries you can use, I use fetch and es6-promise. Adding the following script elements to your page should get things working in Internet ...


3

Your render method is trying to render the entire assignee {assigne}, but React doesn't know how to render that object. Try changing your render to: <div className={styles.CellStyle}> {this.state.ListItems.Assignee.map(assigne=>{return <li key={assigne["odata.id"]}>{assigne.Title}</li>})}</div>


3

Site Users: You can get the site users using pnp.sp.web.siteUsers as given below: $pnp.sp.web.siteUsers.get().then(function(data) { var users = ""; for (var i = 0; i < data.length; i++) { users += data[i].Id + " - " + data[i].Title + "<br/>"; } console.log(users); }); Reference: Pnp-JS-Core: Gets all users from Site ...


3

Consider the following scenario: List A with columns: Title (Single Line Text) ColumnA (Single Line Text) ColumnB (Choice) and List B with columns: Title (Single line of Text) ColumnOne (Single line of Text) ColumnX (Lookup From List A, column A mapped) So the REST Query for List B would be: https://<site url>/_api/web/lists/getbytitle('ListB')/...


3

pnp.sp.web.lists.getByTitle("TestTask").items.add({ Title: TaskNameVal, StartDate: StartDateVal, DueDate: DueDateVal, PercentComplete: CompleteVal, AssignedToId: [AssignedToVal], Body: DescriptionVal, Priority: PriorityVal, Status: statusVal, }).then(r => { alert('Success') $("input").val("") location....


2

Try using something like below: const list = sp.web.lists.getById(ListId); const folderName = 'My subfolder'; list.items.add({ FileSystemObjectType: 1, ContentTypeId: '0x0120' FileLeafRef: folderName }).then(console.log); Reference: Folders and sub folders inside Generic List.


2

Try to use catch in the code snippet to get the exception in the code snippet like below: import { default as pnp, ItemAddResult } from "sp-pnp-js"; private PnPAddItem():void { pnp.sp.web.lists.getByTitle("Jerry").items.add({ EmployeeName : document.getElementById('EmployeeName')["value"], Experience : document.getElementById('Experience')["...


2

I finally got the groupId with the following code: sp.web.select("AllProperties").expand("AllProperties").get().then(w => { console.log(w.AllProperties.RelatedGroupId); });


2

Adding await fixed it! (microsoft should update the docs) Fix: // get terms merged with data from a term set const terms4: (ITerm & ITermData)[] = await store.getTermSetById("0ba6845c-1468-4ec5-a5a8-718f1fb05431").terms.get();


2

Looks like you are using this in Internet Explorer. You need to use a polyfill to use this in IE 11. You can download the package using npm install --save @pnp/polyfill-ie11 command. After that, you can import it in your code as below: import "@pnp/polyfill-ie11"; import { sp } from "@pnp/sp"; sp.web.select("AllProperties").expand("AllProperties").get()....


2

You could use item.userHasPermissions(LoginName,PermissionKind) to check user permission for the folder item. Check @pnp/sp/security https://pnp.github.io/pnpjs/sp/security/


2

I finally got this working. I deleted the node modules and run npm install to retrieve the modules according to package.json. I did try that several times before still getting the same error, but this time I added this command: npm install --save-dev typescript I'm pretty sure I did that too at some point before, but this time everything started working. ...


2

AssignedTo field expects the ID of person/user and not email address. You need set this field like: AssignedToId: 3 Where 3 is ID of user. Additional Reference: How to get the User Principle ID based on the Email Id For multiple selection person or group field you need to use: AssignedToId: { results: [3,11,100] }


2

I am currently working on SPFx with Graph API and it doesn't require any redirection at all for authentication, it will work with the same web part context you're developing right now. Read on https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-msgraph. Previously, I have evaluated @pnp/graph but some graph API does not exist. You will need a reference ...


2

This is the required step while using SP PnP JS module in SPFx solution. Using this code, you set the SPFx context within the SP PnP JS library. Because SharePoint Framework provides a local context to each component we need to set that context within the library. This allows us to determine request urls as well as use the SPFx HttpGraphClient within @pnp/...


1

Finally I got the solution for my question. Instead of Using files.add in sp-pnp-js am used addChunked Method. Refer This Link. Using addChunked method we upload the files as number of little blocks sized 10MB. Using Total number of blocks, add some javascript code to convert percentage.


1

Inside for loop in second SharePoint REST call you need to pass the index (i) to get the Title, like below: temp = json.value[i].Title; Also, as you are using $top=1 so it will return just one item at a time. So, you don't have to use for loop in both cases. In Success function, you use it like: response.json().then((json: any) => { if(json.value &...


1

AAANNDDD found it, thanks to @MikeSmith and @Gautam Sheth, I could make it work. For now, I haven't tested the Hubsites (even if it seems to work). Here is the query I used to get all sites minus personal sites and minus Appcatalog. Make sure to try it on SearQueryTool v2 first ! :) _api/search/query?querytext='(contentclass=STS_Site OR contentclass=...


1

We can also use caml query to get the 50 items and sorted. Below is not an exact working code, I haven't tested, but it will give you an idea to implement it. const xml = "<View><ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /></ViewFields><Query><OrderBy><FieldRef Name='Created' /></OrderBy>&...


1

Try Using something like below: var ItemArray = []; var internalNameOfTitleCol = "Title" var titleColValue = "Here is a dynamic value for list item Title"; var body = {}; body[internalNameOfTitleCol] = titleColValue; ItemArray.push(pnp.sp.web.lists.getByTitle('listdisplayname').items.inBatch(batch).add(body)); Promise.all(ItemArray).then(function() { ...


1

try the below code, terms.get().then((terms:ITerm[])=>{ terms.forEach((term:any)=>{ term.LocalCustomProperties._Sys_Nav_TargetUrl; console.log(term.LocalCustomProperties._Sys_Nav_SimpleLinkUrl); }); }); The above code gives you the simple link. AFAIK, term.LocalCustomProperties doesn't ...


1

Check Term.LocalCustomProperties._Sys_Nav_TargetUrl My debug screenshot: Update: The interface defined in pnpsp. import { taxonomy, ITermStore, ITermSet, ITerms, ITermData, ITerm } from "@pnp/sp-taxonomy";


1

Build your endpoint like given REST endpoint below: siteUrl/_api/web/lists/getbytitle('ListName')/fields?$select=Title,Required Something like: import { sp } from "@pnp/sp"; let web = sp.web; // get the fields in a list web.lists.getByTitle("MyList").fields.get().then(f => { console.log("Field: " + f.Title); console.log("Required: " + f....


1

You are passing Choices array in wrong way. You can create your choices array as given below: var choicesArray = ["Test1", "Test2"]; Then pass it in the items.add() function as: $pnp.sp.web.lists.getByTitle("TestList").items.add({ Testchoicefield: { results: choicesArray }, LastModifiedByDisplayName: _DisplayUserName, LastModifiedByUserId: ...


1

Yes get call is asynchrnous, you should not use render method to get data because render method will be called every time react state will changed and it will again call api causing infinite loop. for you case, on high level I think you can use below. componentDidMount(){ sp.web.get().then((data)=>{ var arbol=[]; arbol.push({name: data....


1

That is mostly due the async nature of the HTTP requests. To upload the file and then set it properties correctly, you can do so as below: pnp.sp.web.getFolderByServerRelativeUrl("/sites/mysite/ConfigDL").files.add(fileOgg.name, fileOgg, true).then(f => { f.file.getItem().then(item => { //update start Below Call to Doc List will update ...


1

You can use the associatedMemberGroup property. When you use it, you dont need to worry about the ID of the group or the group name. It will pick the default member group of the site collection and then you can add the users to it. Sample code: sp.web.associatedMemberGroup.users.add(expLoginName).then(d => { console.log(d); });


Only top voted, non community-wiki answers of a minimum length are eligible