0

In my SharePoint site, I have my document library "MyDocs", and I have a list of companies "Companies"

I added a new lookup column to the document Library "Company" to link a folder to a Company.

Now, I search all folders for company name in title, and I should update the CompanyId.

I didn't found how can I obtain the folder ID to update it, like this:

const searchResults = await sp.search(companyName)

const myFolder: ISearchResult = searchResults.PrimarySearchResults[0];
const folderId = myFolder.WorkId//DocId; // ???? WHAT HERE

// update myFolder.CompanyId from item.companyId
const folderItem = await sp.web.lists.getByTitle("MyDocs").items.getById(folderId);
await folderItem.update({
  CompanyId: item.companyId
});
8
  • You need SharePoint default item ID column value in folderId variable. Check if myFolder result returns Id or ID property in the response and use it. Something like: const folderId = myFolder.Id; OR const folderId = myFolder.ID;. Let me know if it works for you. Nov 22, 2023 at 14:27
  • this is the most evident think i could try, there is no id
    – serge
    Nov 22, 2023 at 14:31
  • 1
    You can select specific managed properties from search like: const searchResults = await sp.search( { Querytext: companyName SelectProperties: ["Title", "ListItemID", "Author"] } ). Try using this ListItemID and see if it works for you. Nov 22, 2023 at 14:45
  • 1
    @GaneshSanap-MVP see my onw answer to that question
    – serge
    Nov 22, 2023 at 15:33
  • 1
    Great, glad it worked for you :) Nov 22, 2023 at 15:33

1 Answer 1

0

After Ganesh suggested to me to include SelectProperties, I did the following

const searchSettings = { SelectProperties: ["Title", "ListItemID"] };
const query = SearchQueryBuilder(mySearch, searchSettings);

// then after search

const myFolder: ISearchResult = searchResults.PrimarySearchResults[0];
const folderId = (myFolder as any).ListItemID as number// WorkId//DocId;

I cry over the very poor documentation on the topic, there is nothing to read to understand that behaviour.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.