SOLVED

SPFx Get label name from managed metadata column?

Regular Contributor

Hi,

 

I am trying to get the label of a managed metadata column from a web part but I a number instead of the name of the metadata (see image below) :

 

Capture.PNG

 

My term storage looks like this:

 

Term Store.png

 

As you see in my query I get a number instead of "Customer1, Customer2..." 

 

This is my code: 

 

const items = await sp.web.lists.getByTitle('Avtal Demo').items
.select('Title,CustomerAgreementNr,AgreementType,ContactPerson,DeliveryType,
AgreementStartDate,AgreementEndDate,AgreementEnded,Customer,LastPriceAdjustment,
NexPriceAdjustment,SalesManager/FirstName, SalesManager/LastName')
.expand('SalesManager')
.get();

items.forEach(item => {
Agreements.push({
AgreementName: item.Title,
CustomerAgreementNr: item.CustomerAgreementNr,
AgreementType: item.AgreementType,
ContactPerson: item.ContactPerson,
DeliveryType: item.DeliveryType,
AgreementStartDate: item.AgreementStartDate,
AgreementEndDate: item.AgreementEndDate,
AgreementEnded: item.AgreementEnded,
LastPriceAdjustment: item.LastPriceAdjustment,
NextPriceAdjustment: item.NexPriceAdjustment,
Customer: item.Customer,
SalesManager: item.SalesManager.FirstName + ' ' + item.SalesManager.LastName,
});
});

Do I need to do something special to get the correct name for the Customer? 

 

Best regards,

Americo

2 Replies
best response confirmed by Americo Perez (Regular Contributor)
Solution

Hi @Americo Perez 

 

@Marc Anderson has a great blog post where he shared a JavaScript function to deal with this issue. I use it all the time and it simply works! 

https://sympmarc.com/2017/06/19/retrieving-multiple-sharepoint-managed-metadata-columns-via-rest/ 

 

Hope this helps

Thanks @Joel Rodrigues it helped!

It wasn't that hard!

 

Regards..