cancel
Showing results for 
Search instead for 
Did you mean: 

Displaying field value

Former Member
0 Kudos

Hi, Kindly see my code below. I need to display values of field "PRODUCT_STATUS" (eg: for every record it contains Active/Inactive) and "PRODUCTS_TERMINATION_DATE". Please help, I missing something at code level.

RepositorySchema objRepositorySchema = null;

objRepositorySchema = getRepositorySchemaCommand.getRepositorySchema();

TableId mainTableId = new TableId(1);

ResultDefinition rd = null;

rd = new ResultDefinition(mainTableId);

Record taxoSubClassRecs[] = (Record[])null;

RecordId recordIdsList[] = (RecordId[])null;

String strStatus = objRepositorySchema.getFieldId("MDM_PRODUCTS","PRODUCTS_STATUS").toString();

System.out.println("strStatus>>>"+strStatus );

//String strID = objRepositorySchema.getFieldId("Products","ID").toString();

rd.addSelectField(new FieldId(strStatus));

FieldSearchDimension fsd = new FieldSearchDimension(new FieldId(strStatus));

TextSearchConstraint tscTypeRoot = new TextSearchConstraint("ACTIVE",4);

Search search = new Search(mainTableId);

search.addSearchItem(fsd, tscTypeRoot);

RetrieveLimitedRecordsCommand limitingCommand = new RetrieveLimitedRecordsCommand(connections);

limitingCommand.setSession(sessionId);

limitingCommand.setResultDefinition(rd);

limitingCommand.setSearch(search);

try {

limitingCommand.execute();

//RecordResultSet records = limitingCommand.getRecords();

} catch (CommandException e2) {

// TODO Auto-generated catch block

e2.printStackTrace();

}

if(limitingCommand.getRecords()!= null){

System.out.println("Number of records:"+limitingCommand.getRecords().getCount());

Record [] records = limitingCommand.getRecords().getRecords();

for (int i = 0; i < records.length; i++) {

System.out.println("Record \"i\": Value "+records<i>.getDisplayValue());

}

}else{

System.out.println("no records:");

}

Accepted Solutions (1)

Accepted Solutions (1)

Greg_Austin
Active Participant
0 Kudos

Read those specific fields from the Record object with the getFieldValue method. Make sure those fields are added to the ResultDefinition that the search uses. Using getDisplayValue will only get the fields marked as display fields.

-Greg

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi, for displaying values from lookup field I used the below code and it resolved the issue

Thanks everyone for kind help

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);

}

}

}

Former Member
0 Kudos

Greg, I found another thread response as

Record record = command.getRecords().getRecord(0);

//Main table code = Customers,

//Country as lookup table's field code in maintable

Record[] countries = record.findLookupRecords(

repSchema.getFieldId("Customers", "Country"));

wdComponentAPI.getMessageManager().reportSuccess(

" Country Field Code " + repSchema.getFieldId("Customers", "Country"));

//Name : Field in country table, with code "Name"

wdComponentAPI.getMessageManager().reportSuccess(

" Country Name Code " + repSchema.getFieldId("Countries", "Name"));

//Number of lookup elements attached to the main record.

wdComponentAPI.getMessageManager().reportSuccess(

" countries length = " + countries.length);

//display the name of first country record mapped to the main table.

wdComponentAPI.getMessageManager().reportSuccess(

" Country = " + countries[0].getDisplayValue());

But when I try to execute say,

Country = " + countries<i>.getDisplayValue());

I get blank value again. Is it related to my problem? if yes, why I get blank message?

Thanks

Greg_Austin
Active Participant
0 Kudos

Are you certain that your main table record that is in position 0 has country records attached? Are you certain the country in position 0 has a value in the display field? I recommend printing out the records unique field so you know exactly which record you are working with. Verify the main table record has a country attached and then verifying that all countries attached to this main table record have values in the display field.

Former Member
0 Kudos

I am able to retireve the date values Greg. Thank you.

Any how , i am still working to get the Status lookup field values.

I get blank as a result of

if(records<i>.getLookupDisplayValue(objRepositorySchema.getFieldId("MDM_PRODUCTS","PRODUCTS_STATUS"))!=null)

{

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

System.out.println("mdmval value is >>>"+mdmval);

}

I am trying to resolve the same

Thanks

Former Member
0 Kudos

Hi Greg,

I am still facing the problem.

How to print the value ?

Also in DateTimeValue I am not able to find getDate() method

Could you please help me with a piece of code for printing the value and date?

Thanks

Greg_Austin
Active Participant
0 Kudos

What can't you print? Are you using getLookupDisplayValue on the Record class? Do you have display fields on the lookup table and are you certain the main table record you are printing has a value for that lookup table selected?

The getDate method didn't come around until SP6 patch 2. You will have to build a date yourself from the DateTimeValue using the getDay, getYear, etc. Google java Date if you need help assembling a Date object or you can just print it out with something like System.out.println(dtv.getMonth() + "/" + dtv.getDay + "/" + dtv.getYear());

Former Member
0 Kudos

Hi Greg, Still I face the issue

Pls have a look at my code below

if(limitingCommand.getRecords()!= null){

System.out.println("Number of records:"+limitingCommand.getRecords().getCount());

Record [] records = limitingCommand.getRecords().getRecords();

//System.out.println(records);

for (int i = 0; i < records.length; i++) {

//System.out.println("Record "i": Value "+records<i>.getFieldValue(objRepositorySchema.getFieldId("MDM_PRODUCTS","PRODUCTS_STATUS")).toString());

//System.out.println("Date "i": Value "+records<i>.getFieldValue(objRepositorySchema.getFieldId("MDM_PRODUCTS","PRODUCTS_TERMINATION_DATE")).toString());

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

System.out.println("mdmval>>>"+mdmval.toString());

if(records<i>.getLookupDisplayValue(objRepositorySchema.getFieldId("MDM_PRODUCTS","PRODUCTS_STATUS"))!=null){

System.out.println("qqq>>>"+records<i>.getLookupDisplayValue(objRepositorySchema.getFieldId("MDM_PRODUCTS","PRODUCTS_STATUS")).toString());

}

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

System.out.println("mdmval1>>>"+mdmval1.toString());

if (mdmval instanceof DateTimeValue) {

DateTimeValue dtv = (DateTimeValue) mdmval1;

//java.util.Date d = dtv.getDate();

//now do whatever you need to do to the date

}

}

}else{

System.out.println("no records:");

}

I get the output as

Number of records:1000

mdmval>>>R2

mdmval1>>>[Null]

mdmval>>>R1

mdmval1>>>[Null]

mdmval>>>R1

mdmval1>>>07/14/2009

mdmval>>>R1

mdmval1>>>[Null]

mdmval>>>R1

mdmval1>>>[Null]

mdmval>>>R1

mdmval1>>>[Null]

Any idea? Thanks

Greg_Austin
Active Participant
0 Kudos

mdmval is printing out as R1 and R2 because of the line System.out.println("mdmval>>>"+mdmval.toString()); Don't ever directly print an MdmValue object, it doesn't make sense.

Don't do this:

MdmValue mdmval1 = records.getFieldValue(objRepositorySchema.getFieldId("MDM_PRODUCTS","PRODUCTS_TERMINATION_DATE"));

System.out.println("mdmval1>>>"+mdmval1.toString());

Again printing a MdmValue isn't what you want. Handle the printing inside the if statement (also change the mdmval in the if statement to mdmval1).


if (mdmval1 instanceof DateTimeValue) {
	DateTimeValue dtv = (DateTimeValue) mdmval1;
 	java.util.Date d = dtv.getDate();
  	SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
	System.out.println("Date: " + sdf.format(d));
}

Many of your dates are null so they are probably empty in MDM. If you want to get over 1000 records use the setPageSize on the RetrieveLimitedRecordsCommand.

Former Member
0 Kudos

Hi Greg,

Thanks for the input.

As I am new to MDM , missing out few steps.

As you said I tried to casting the value to String.

In my case PRODUCTS_STATUS is a Lookup and Termination Date is Literal Date.

How to get the specific values? I searched in Forum, but didnt get exact answer

Thanks

Greg_Austin
Active Participant
0 Kudos

Sure thing. First of all always check the type of object before casting to a specific type. MdmValue has several subclasses, the method getFieldValue returns the MdmValue that you must cast. If the field is empty in MDM this field is returned as a NullValue and casting it to another type will result in a class cast exception.


MdmValue mdmval = rec.getFieldValue(<FieldId>);
if (mdmval instanceof DateTimeValue) {
	DateTimeValue dtv = (DateTimeValue) mdmval;
	java.util.Date d = dtv.getDate();
       //now do whatever you need to do to the date
}

Lookup values can work a little different. If you only need the fields marked as display fields on the lookup table you can use the getLookupDisplayValue method and get the String representation without using getFieldValue.


rec.getLookupDisplayValue(<FieldId>);

Former Member
0 Kudos

Hi ,

I tried with

Record [] records = limitingCommand.getRecords().getRecords();

for (int i = 0; i < records.length; i++) {

System.out.println("Record "i": Value "+records<i>.getFieldValue(objRepositorySchema.getFieldId("MDM_PRODUCTS","PRODUCTS_STATUS")).toString());

}

}else{

System.out.println("no records:");

}

I get the result as

Number of records:1000

Record 0: Value R1

Record 1: Value R1

Record 2: Value R1

Record 3: Value R1

Record 4: Value R1

Record 5: Value R1

Record 6: Value R1

Record 7: Value R1

Record 8: Value R1

Record 9: Value R1

Any suggestions how to get the field value?

Also I have mentioned as

FieldSearchDimension fsd = new FieldSearchDimension(new FieldId(strStatus));

TextSearchConstraint tscTypeRoot = new TextSearchConstraint("ACTIVE",4);

Will this only return records with "ACTIVE" value? how to get all the record values?

Thanks

Prabhu.M...

Greg_Austin
Active Participant
0 Kudos

The method getFieldValue doesn't return a String representation of the value, but an MdmValue object. This object can then be cast other objects (StringValue, IntegerValue, LookupValue) depending on what type of field you are reading, text, integer, lookup, etc. You can use these objects to get the actual fields value. See the javadocs for more information on these objects.

If you want to get all of the records, not just the "ACTIVE" ones, you need to remove the search constraint. A Search object doesn't need to have any constraints added, just create the Search object and pass it to the RetrieveLimitedRecordsCommand.

Former Member
0 Kudos

Hi Prabhu,

You can use the following code to retrieve the lookup value based on the Record Identifier (i.e. R1, R2...). Just pass the required Table Id, Field Id and Record Id to the below command and you will get the Value.

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() ;

Hope this helps!!

Regards,

Arafat