cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AfroBadger
New Member

Searching TermStore metadata coloum from SharePoint List in PowerApp

I'm hoping someone can help me here. My objective is to filter a Sharepoint list by TermStore (metadata) items

 

I have a SharePoint List that I am using for testing.  This has basic layout of 

 

TestList

TitleMetadata
"Test Title1"

"meta-a","meta-b"

"Test Title2"

"meta-a","meta-c"

"Test Title3"

"meta-c"

 

The metadata column is a look-up to the SharePoint term store.

 

So far, I have been able to do the following successfully.

 

Create listbox of metadata entries.

\\This is set within App.OnStart
Clear(colMetadataLabels);
ForAll(
Choices(TestList.Metadata) As newData,
Collect(colMetadataLabels,
newData.Label
)
);

 I can then use ColMetaDataLabels within a Listbox showing the field "Value"

 

if I view the output of all fields of the above function, I see the following: -

AfroBadger_0-1670334274223.png

As you can see the Wssid value is set to "-1" , Not sure why this is.

 

I can pull out the metadata entries for the first record in TestList with the following

Set(colFirstEntry,
First(TestList.Metadata.MetaData.MetaData).MetaData
);

I have no idea why the nesting of the metadata (termstore) is so many levels deep.  But this will return a table with the following

 

AfroBadger_1-1670334617253.png

Note: You can see that the Wssid is preserved here.

 

I can even loop through each entry to retrieve each records metadata entry.

Clear(colAllMetadataentries);

ForAll(
TestList,
Collect(colAllMetadataentries,
ThisRecord.Metadata
)
);

AfroBadger_2-1670335151221.png

 

The Problem

My development of this filter has ground to a haul as I cannot find a way of linking the Title of each entry with the retrieved metadata entries.  If I try to add a column then nothing happens.  I am assuming that the table being returned in "colAllMetadataentries" are locked somehow

 

I have researched that Termstores records are stored as odata.type Microsoft.Azure.Connectors.SharePoint.SPListExpandedTaxonomy.

 

This is where my knowledge ends and hope someone is up for the challenge to help.  😀

 

 

 

1 REPLY 1
AfroBadger
New Member

Here is an update......

 

I have now managed to filter using the following method.  It seems clunky but it works for now.  If anyone has a better method, then please let me know.

 

//This is all run in App.OnStart()
//Clear collections

Clear(colMetadataLabels);
Clear(colTemp);

//Collects all MetaData Lables to be used in List Box
ForAll(
Choices(TestList.Metadata) As newData,
Collect(colMetadataLabels,
newData.Label
)
);

// This creates a temporary table that will be used to link
// metadata entries with the ID of records in TestList

Set(tempTable,Table({ID:0,Title:"",MetaData:""}));

//Table needs to be stored as a collection to work - Don't no why
ClearCollect(colTemp,tempTable);

//Removes first blank entry as I currently have no idea how to create a table without entering a blank entry 😕

Remove(colTemp,First(tempTable));

//itterate through each metadata entry for each entry by using a nested ForALL statement
// results are written to the colTemp collection
ForAll(
TestList As MyData,
ForAll(MyData.Metadata As MyData2,
Patch(colTemp,
Defaults(colTemp),
{ID: MyData.ID},
{Title: MyData.Title},
{MetaData: MyData2.Label}
)
)
)

As you can see above, I am having to create a temporary table that I can store the TestList ID and the metadata string value.  This Table is then converted to a Collection, which is then Patched with the ID, Title and Metadata name

 

I then created a Listbox with the Items set to colMetadataLabels.

 

I also set the following to Listbox.OnChange

Clear(ColMetaItems);

ForAll(
(Metadata_ListBox2.SelectedItemsText) As myData,
Collect(ColMetaItems,
Filter(colTemp,
myData.Value = MetaData And !(ID in ColMetaItems.ID)
)
)
);

ForAll(
ColMetaItems As myFilter,
Collect(colMetaFilterResults,
Filter(TestList,
myFilter.ID = ID And !(ID in colMetaFilterResults.ID)
)
)
)

 

Please help me confirm if this is madness that could be compressed to half the lines or a good way.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,172)