Cannot get related items with PnPjs search on workflow task content type

Milind Saraswala 1 Reputation point
2020-09-10T15:08:30.92+00:00

I am working on SPFx Project and using PnPjs search. My requirement is to search for pending workflow task for that I have created result source at site collection level. Builder query as below

{searchTerms} ContentTypeId:0x0108* Path:{SiteCollection.URL} WorkflowOutcomeOWSTEXT:Pending

Now I am using SPFx to retrieve data. I cannot get related item of the task or related item id for the original item. Other than that I get all data. Let me know I am doing wrong or there is some issue pnpjs

My code as below (SPFx v2.0.6 and SharePoint Online/2019)

const getContentTypeData = async (rowLimit: number, sourceId: string, querytext: string, selectedProperties: string[]) => {
const appSearchSettings: ISearchQuery = {
RowLimit: rowLimit,
EnableInterleaving: true,
SourceId: sourceId,
TrimDuplicates: false,
Querytext: querytext,
SelectProperties: selectedProperties
}
const searchResults: SearchResults = await sp.search(appSearchSettings)
return searchResults
}
const selectedProperties = ['ListItemID', 'Path', 'Title', 'HitHighlightedSummary', 'LastModifiedTime', 'ParentLink', 'RelatedItems']
const rowLimit = 10
let queryText = AssignedTo:"${displayName}" // Passing current user displayName
getContentTypeData(rowLimit, searchSourceId.PendingTask, queryText, selectedProperties)
.then((r: SearchResults) => {
setPendingTask({ totalRows: r.TotalRows, primarySearchResults: r.PrimarySearchResults })
})
.catch(console.warn)

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
1,457 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,348 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Baker Kong-MSFT 3,761 Reputation points
    2020-09-11T07:51:54.91+00:00

    Hi @Milind Saraswala ,

    I am able to reproduce this issue here, the 'RelatedItems' property always returns null.

    24045-image.png

    Based on below docs, SelectProperties must be managed properties and their retrievable flag should be true.

    24055-image.png

    'RelatedItems' has not been crawled, so we need to map it to a managed property.

    24101-image.png

    Result:

    24068-image.png

    Note: Please make sure the task really has related items and it may cost some time for crawling.

    Best Regards,
    Baker Kong


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.