SOLVED

SPFx Get label name from managed metadata column?

%3CLINGO-SUB%20id%3D%22lingo-sub-390185%22%20slang%3D%22en-US%22%3ESPFx%20Get%20label%20name%20from%20managed%20metadata%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-390185%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20get%20the%20label%20of%20a%20managed%20metadata%20column%20from%20a%20web%20part%20but%20I%20a%20number%20instead%20of%20the%20name%20of%20the%20metadata%20(see%20image%20below)%20%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20357px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F100416iD60E9EB85DC5FD7F%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22Capture.PNG%22%20title%3D%22Capture.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20term%20storage%20looks%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20172px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F100417i749E3CE9995E49A7%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22Term%20Store.png%22%20title%3D%22Term%20Store.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20you%20see%20in%20my%20query%20I%20get%20a%20number%20instead%20of%20%22Customer1%2C%20Customer2...%22%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20my%20code%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CPRE%3Econst%20items%20%3D%20await%20sp.web.lists.getByTitle('Avtal%20Demo').items%3CBR%20%2F%3E%20%20%20%20%20%20.select('Title%2CCustomerAgreementNr%2CAgreementType%2CContactPerson%2CDeliveryType%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20AgreementStartDate%2CAgreementEndDate%2CAgreementEnded%2CCustomer%2CLastPriceAdjustment%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20NexPriceAdjustment%2CSalesManager%2FFirstName%2C%20SalesManager%2FLastName')%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20.expand('SalesManager')%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20.get()%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%20%20%20%20%20%20%20items.forEach(item%20%3D%26gt%3B%20%7B%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20Agreements.push(%7B%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20AgreementName%3A%20item.Title%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20CustomerAgreementNr%3A%20item.CustomerAgreementNr%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20AgreementType%3A%20item.AgreementType%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20ContactPerson%3A%20item.ContactPerson%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20DeliveryType%3A%20item.DeliveryType%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20AgreementStartDate%3A%20item.AgreementStartDate%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20AgreementEndDate%3A%20item.AgreementEndDate%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20AgreementEnded%3A%20item.AgreementEnded%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20LastPriceAdjustment%3A%20item.LastPriceAdjustment%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20NextPriceAdjustment%3A%20item.NexPriceAdjustment%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20Customer%3A%20item.Customer%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20SalesManager%3A%20item.SalesManager.FirstName%20%2B%20'%20'%20%2B%20item.SalesManager.LastName%2C%3CBR%20%2F%3E%20%20%20%20%20%20%7D)%3B%3CBR%20%2F%3E%7D)%3B%3C%2FPRE%3E%3CP%3EDo%20I%20need%20to%20do%20something%20special%20to%20get%20the%20correct%20name%20for%20the%20Customer%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%20regards%2C%3C%2FP%3E%3CP%3EAmerico%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-390185%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-390395%22%20slang%3D%22en-US%22%3ERe%3A%20SPFx%20Get%20label%20name%20from%20managed%20metadata%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-390395%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9907%22%20target%3D%22_blank%22%3E%40Joel%20Rodrigues%3C%2FA%3E%26nbsp%3Bit%20helped!%3C%2FP%3E%3CP%3EIt%20wasn't%20that%20hard!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards..%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-390220%22%20slang%3D%22en-US%22%3ERe%3A%20SPFx%20Get%20label%20name%20from%20managed%20metadata%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-390220%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F117034%22%20target%3D%22_blank%22%3E%40Americo%20Perez%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F83%22%20target%3D%22_blank%22%3E%40Marc%20Anderson%3C%2FA%3E%26nbsp%3Bhas%20a%20great%20blog%20post%20where%20he%20shared%20a%20JavaScript%20function%20to%20deal%20with%20this%20issue.%20I%20use%20it%20all%20the%20time%20and%20it%20simply%20works!%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fsympmarc.com%2F2017%2F06%2F19%2Fretrieving-multiple-sharepoint-managed-metadata-columns-via-rest%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsympmarc.com%2F2017%2F06%2F19%2Fretrieving-multiple-sharepoint-managed-metadata-columns-via-rest%2F%26nbsp%3B%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20helps%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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
Highlighted
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

Highlighted

Thanks @Joel Rodrigues it helped!

It wasn't that hard!

 

Regards..