Skip to Content
avatar image
Former Member

Lookup Flat value from Main Table returns R2

Hi All

Im using the sample BUPA repository on MDM 5.5

Using RetrieveLimitedRecordsCommand to retrieve records, and traversing through a RecordResultSet object

RecordResultSet rs=ret.getRecords();

for(int k=0;k<rs.getCount();k++)

{

Record r=rs.getRecord(k);

for (int l=0;l<fields.length;l++){

response.write(" "r.getFieldValue(fid[l])" / ");

}

}

This displays all the values of every field in each row of the main table.

Whenever it encounters a value which comes from a Flat Lookup Table or so, it just returns a record Id e.g. R2

How can I display that value ?

Also tell me how to lookup a Taxonomy values. Using the MDM Webservice, it shows the exact value. But using the Java API Im a bit confused

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • avatar image
    Former Member
    Jul 27, 2009 at 03:56 AM

    Hi Prem,

    For Lookup tables, instead of getFieldValue() try using getLookupDisplayValue().

    Regards,

    Jitesh Talreja

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 27, 2009 at 08:24 AM

    Hi Prem,

    The reason why you are getting the Value R2 is because it is pointing to a lookup table. You need to take this Record Identifier value and get the value against this identifier by using the below code:

    Note: Use the tableID & Field ID for the lookup table that maintable field is pointing to. LookupFieldID is for the field whose vaue you want to get from the lookup table.

    ResultDefinition objResultDefiniton = new ResultDefinition(new TableId(LookupTableID));
    objResultDefiniton.addSelectField( new FieldId( (LookupstrFieldID ) ) );
    			
    RetrieveRecordsByIdCommand objRecordsByIDCommand = new RetrieveRecordsByIdCommand(objConnectionAccessor);
    objRecordsByIDCommand.addId( new RecordId(LookupRecordID));
    objRecordsByIDCommand.setSession(strUserSessionID);
    objRecordsByIDCommand.setResultDefinition(objResultDefiniton);
    objRecordsByIDCommand.execute();
    
    String strFieldValue = null;
    if(objRecordsByIDCommand.getRecords().getCount() > 0)
    strFieldValue = objRecordsByIDCommand.getRecords().getRecord(0).getFieldValue( new FieldId( LookupFieldID )) .toString() ;
    

    Let me know if you still face any issues.

    Regards,

    Arafat

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Prem,

      You can create a RecordId object as below by passing the record id in the form of string "R2":

      RecordId objRecordId = new RecordId(strRecordId);

      RecordId objRecordId = new RecordId("R2");

      Cheers,

      Arafat

  • avatar image
    Former Member
    Jul 28, 2009 at 01:36 PM

    Hi Prem,

    I had a similar issue. Its resolved now.

    Please see my code below

    for(int i =0;i<objRecordResultSet.getCount() ; i++)

    {

    strRecordId = objRecordResultSet .getRecord(i).getId().toString() ;

    //int intRecordId = Integer.parseInt(strRecordId);

    int intRecordId = objRecordResultSet .getRecord(i).getId().getIdValue();

    MdmValue mdmval = records<i>.getFieldValue(objRepositorySchema.getFieldId("MDM_PRODUCTS","PRODUCTS_STATUS"));

    RetrieveRecordsByIdCommand objRecordsByIDCommand = new RetrieveRecordsByIdCommand(connections);

    objRecordsByIDCommand.addId( new RecordId(strRecordId));

    objRecordsByIDCommand.setSession(sessionId);

    objRecordsByIDCommand.setResultDefinition(rd);

    try {

    objRecordsByIDCommand.execute();

    } catch (CommandException e3) {

    // TODO Auto-generated catch block

    e3.printStackTrace();

    }

    String strFieldValue = null;

    if(objRecordsByIDCommand.getRecords().getCount() > 0)

    if(objRecordsByIDCommand.getRecords().getRecord(0).getFieldValue( new FieldId( objRepositorySchema.getFieldId("MDM_PRODUCTS","PRODUCTS_STATUS")))!= new NullValue())

    {

    strFieldValue = objRecordsByIDCommand.getRecords().getRecord(0).getFieldValue( new FieldId( objRepositorySchema.getFieldId("MDM_PRODUCTS","PRODUCTS_STATUS"))).toString();

    }

    for(int k = 0; k<strStatus1.length;k++)

    {

    String we = statusRecordResultSet.getRecord(k).getId().toString() ;

    if(we.equals(strFieldValue)){

    String strValue3 = statusRecordResultSet.getRecord(k).getFieldValue(objRepositorySchema.getFieldId("New_Code9","STATUS_STATUS")).toString() ;

    System.out.println("Product Status>>"+strValue3);

    }

    }

    }

    Add comment
    10|10000 characters needed characters exceeded

    • Hi,

      As Jitesh said, use findlookuprecords.

      ReturnType Record[]

      findLookupRecords(FieldId lookupFieldId)

      Find supported lookup record (or records for multi-value case) in cache of result set for the specified lookup field.

      If you are saying it returns you R2, i would disagree because the return type of the above command is a array of records.

      R2 is a type record Id and not record Id .

      As it returns you array, use the element of the array and do a

      record.getDisplayField()

      or

      record.getFieldValue(FieldId of the field in lookup table)

      Somewhere your question was how to get the table Id, you can get the table Id of any table using the table code and repository schema.

      repositoryschema.getTableId( tablecode ) ;

      or you can directly get the field id using

      repositoryschema.getTableId( tablecode, fieldCode ) ;

      This is the simplest way to do it, so would advice not to use anything else which unnacessarily complicates the code.

      The one thing you want may want to do is to add the result definition of the look up tables in the retrieve command using

      retrievelimitedrecordscommand.setSupportingResultDefinitions( resultdefinition[]) ;

      This is optional step but just adds an extra step of surity.

      Let me know the code that you used to get there

      Regards,

      Nitin

  • Dec 26, 2009 at 09:57 AM

    Hi,

    I want to use .findLookupRecords command to retrieve non-display field value of the lookup table.

    MainTableRecords.getRecord(0).findLookupRecords(<LookupField ID>)[0].getFieldValue(<non-display field Id>));

    When I use the above statement, I am getting "Field not found in the table" exception.

    I am not adding any ResultDefinition and fields of the lookup table. I know, I am missing some thing here. Can you please help me with this?

    Thanks and best regards,

    Arun prabhu S

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      To use findLookupRecords(), you'll need to also use setSupportingResultDefinitions(). Here's what to do:

      First, create a result definition for your lookup table. You can include as many fields from the lookup table as you need, and they can be either display or non-display fields, it doesn't matter.

      Second, put this result definition into an array of ResultDefinition objects. This allows you to get records from multiple lookup tables in the same call. If you only have one lookup result definition, it's simply a length-1 array.

      Finally, on your RetrieveLimitedRecordsCommand (or RetrieveRecordsByIdCommand), call setSupportingResultDefinitions, passing in your ResultDefinition array.

      Now, your call to findLookupRecords will return the fields in your lookup ResultDefinition, and you can access these records like any other record.

      This post was also helpful in figuring this out, and it has some sample code:

      lookup-record-id-from-lookup-table

      Hope this helps,

      Shawn

  • Dec 26, 2009 at 12:02 PM

    I missed to add supporting result definition

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 08, 2010 at 04:54 PM

    Helllo Prem,

    Cna you please explain me the scenario? WHy do you need to do it programatically? WHy you can not do it using Standard MDM functionality? It will help me undertand your issue.

    Shakil

    SAP USA PA

    Add comment
    10|10000 characters needed characters exceeded