Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9076

Re: Retrieve Multilingual text for a Attribute

$
0
0

Hello Pankaj,

 

There are two possible ways to achieve this:

 

 

1. When creating a user context use the region that you want to present the values in like so:

         

new UserSessionContext("MDSName", "RepositoryName","Region", "UserName");

 

where "Region" is replaced by the wanted region(i.e. French [FR], English [US], etc.)

 

Now you can use the method

 

com.sap.mdm.extension.data.RecordEx.getAttributeDisplayValue(FieldId taxonomyFieldId, AttributeId attrId, int regionalLayer)

 

With the needed regionLayer (CURRENT, INHERITED or PRIMARY_INHERITED– notice that CURRENT will return null if no value exists in the chosen language).

 

This method returns an array of strings (in case it's a multi value attribute) that are the attribute's value(s) in the language you used when creating the session context.

Check the method's Javadoc for more info.

 

 

 

2. Log in with any language and use the MdmValueFormatter class to get to the required value like in this code snippet:
 

RetrieveLimitedRecordsExCommand retCom= newRetrieveLimitedRecordsExCommand(context);
retCom.setResultDefinition(resultDefinition);
retCom.setSearch(search);
retCom.execute();
//In this instance I retrieved only one (known) record here
RecordEx record = (RecordEx) retCom.getRecords().getRecord(0); 
//The (Categories table)record that is pointed to by the lookup field value
Record[] lookupRecord = record.findLookupRecords(categoryFieldId);  
RetrieveAttributeLinksCommand attrLinksCom = new RetrieveAttributeLinksCommand(context);
attrLinksCom.setTaxonomyTableId(_repositorySchema.getTableId("CATEGORIES"));
attrLinksCom.setRecordId(lookupRecord[0].getId());
attrLinksCom.execute();
AttributeProperties[] attributeProps = attrLinksCom.getAttributes();
/* This creates the French [FR] region properties, for runtime usage you can either 1. use UserSessionContext.getRegion() if you logged in with
* the needed language,
* 2. Prepare an enum of the locales used in your repository (easiest and best way to preserve performance)
* 3. Use  GetRepositoryRegionListCommand to get all of the regions in your repository and use the one you need according to the region code.
*/
RegionProperties frRegion = new RegionProperties("French [FR]", Locale.FRENCH, "fre___");
for(int atrId=0; atrId<attributeProps.length; atrId++){       //Gets the value from the current attribute according to index atrId       MdmValue attrVal = record.getAttributeValue(categoryFieldId, attributeProps[atrId].getId());       //Uses MdmValueFormatter helper class to format the value so that it appears in the language defined by the region supplied       String[] formattedValues = MdmValueFormatter.formatAttributeValue(attributeProps[atrId], attrVal, frRegion,                                                MetadataManager.getInstance().getRepositoryDimensions(context));
}

 

Now String[] formattedValues will contain all of the values(if multi valued, only one if not) of this attribute in the language specified.

 

 

Regards,

Dan.


Viewing all articles
Browse latest Browse all 9076

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>