cancel
Showing results for 
Search instead for 
Did you mean: 

DisplayValue of a LOV

Experimenter
Experimenter

Hi all ,

 

after some month i begin to go deeper in teamcenter soa matter.

How can i get display value of a LOV?

I can retrieve value  with LOVRestBindingStub but i  didn't found a way to obtain the list of display value of a attribute.

 

Thanks in advance

1 REPLY

Re: DisplayValue of a LOV

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi,

I found the folllowing example in GTAC FAQ. It is about dynamic LOV but maybe it helps you to get the values for your set-up. 

It is based on the HelloTeamcenter example that comes with the SOA libs.

 

package com.teamcenter.hello;

import java.util.Calendar;
import java.util.Map;
import java.util.Set;

import com.teamcenter.clientx.AppXSession;

import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException;
import com.teamcenter.services.strong.core.DataManagementService;
import com.teamcenter.services.strong.core.LOVService;
import com.teamcenter.services.strong.core.SessionService;
import com.teamcenter.services.strong.core._2011_06.LOV.LOVAttachment;
import com.teamcenter.services.strong.core._2011_06.LOV.LOVAttachmentsInput;
import com.teamcenter.services.strong.core._2011_06.LOV.LOVAttachmentsResponse;
import com.teamcenter.services.strong.core._2013_05.LOV.InitialLovData;
import com.teamcenter.services.strong.core._2013_05.LOV.LOVSearchResults;
import com.teamcenter.services.strong.core._2013_05.LOV.LOVValueRow;
import com.teamcenter.services.strong.core._2013_05.LOV.LovFilterData;
import com.teamcenter.soa.client.model.ModelObject;
import com.teamcenter.soa.client.model.ServiceData;
import com.teamcenter.soa.client.model.strong.Fnd0ListOfValuesDynamic;
import com.teamcenter.soa.client.model.strong.User;
import com.teamcenter.soa.common.ObjectPropertyPolicy;
import com.teamcenter.soa.exceptions.NotLoadedException;

public class LOV
{
	private DataManagementService dmService;
	private LOVService lovService;
	
	private final String lovUID = "DVYdH9oh4Zi2AB";

	private User user;

	private Fnd0ListOfValuesDynamic dynamicLOV;

	public LOV(User usr)
	{
		dmService = DataManagementService.getService(AppXSession.getConnection());
		lovService = LOVService.getService(AppXSession.getConnection());
		
		user = usr;
		setObjectPolicy();
	}
	
	public boolean loadObject()
	{
		ServiceData sData = dmService.loadObjects(new String[]{ lovUID });

		if(sData.sizeOfPlainObjects() > 0)
		{
			ModelObject mObj = sData.getPlainObject(0);

			if(mObj instanceof Fnd0ListOfValuesDynamic)
			{
				dynamicLOV = (Fnd0ListOfValuesDynamic) mObj;

				return true;
			}
		}

		return false;
	}
	
	public void listDynamicLOV()
	{
		/* BMIDE definition of the LOV used:
		<LOVDynamic name="G4ADataset" description="" usage="Exhaustive"

		queryClause="SELECT qid FROM Dataset WHERE &quot;object_type&quot; = &quot;FullText&quot;"
       	dataType="PROP_string" queryType="Dataset" 
		lovValueAttribute="object_name"
       	lovValueDescriptionAttribute="object_desc"/> */
		
		InitialLovData input = new InitialLovData();
		LovFilterData filter = new LovFilterData();
		
		filter.sortPropertyName = "object_name";
		filter.order = 0;
		filter.numberToReturn = 100;
		filter.maxResults = 100;
		
		input.lov = dynamicLOV;
		input.filterData = filter;
		
		LOVSearchResults result = lovService.getInitialLOVValues(input);
			
		if(!ServiceDataError(result.serviceData))
		{
			for(LOVValueRow row : result.lovValues)
			{
				Map<String, String[]> map = row.propDisplayValues;
				
				for(String key : map.keySet())
				{
					System.out.println("UID: " + row.uid + ", key: "+ key + ", value: " + map.get(key)[0]);
				}
			}
		}
	}
	
	protected boolean ServiceDataError(final ServiceData data)
	{
		if(data.sizeOfPartialErrors() > 0)
		{
			for(int i = 0; i < data.sizeOfPartialErrors(); i++)
			{
				for(String msg : data.getPartialError(i).getMessages())
					System.out.println(msg);
			}

			return true;
		}

		return false;
	}

	protected void setObjectPolicy()
	{
		SessionService session = SessionService.getService(AppXSession.getConnection());
		ObjectPropertyPolicy policy = new ObjectPropertyPolicy();
		policy.addType("ListOfValues", new String[]{ "lov_type", "lov_desc", "lov_name" });
		session.setObjectPropertyPolicy(policy);
	}
}