cancel
Showing results for 
Search instead for 
Did you mean: 

ModifyRecordCommand for Lookup Field (PDF)

satishra
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

I have the following method to set the Lookup Field value of main table record. I am not seeing any error in the code or in the log file. But i dont see lookup field being updated via data manager.. basically i should be able to launch a pdf file (via the data manager..from main table record lookup field..) for the uploaded with this method. that's the testing part.. please let me know if you have encountered any such problem or if there is something wrong with this program..thanks..

public static void attachBlobToRecord(Repository rep, String mainTableName, String fileFieldName, int mainTableRecordId, RecordId blobRecordId)

throws Exception{

//Repository rep = new Repository(settings);

try

{

rep.initialize();

logMessage("MainTableRecordId:" + mainTableRecordId);

logMessage("blobRecordId:" + blobRecordId.getIdValue());

logMessage("blobRecordId:" + blobRecordId.getString());

FieldId field = null;

field = rep.getFieldId(mainTableName, "ID");

FieldSearchDimension fieldSearchDimension = new FieldSearchDimension(field);

//TextSearchConstraint textSearchConstraint = new TextSearchConstraint("Mr", TextSearchConstraint.EQUALS);

TextSearchConstraint textSearchConstraint = new TextSearchConstraint(Integer.toString(mainTableRecordId), TextSearchConstraint.EQUALS);

TableId tableId = rep.getTableId(mainTableName);

Search search = new Search(tableId);

//search.addSearchItem(fieldSearchDimension, textSearchConstraint);

search.addSearchItem(fieldSearchDimension, textSearchConstraint);

ResultDefinition rd = new ResultDefinition(tableId);

rd.addSelectField(field);

//rd.setFieldSelectionType(rd.ALL_FIELDS);

//rd.setSelectFields(tablescheme.

//Fields[] fields = new Field

TableSchema tablescheme = rep.getRepositorySchema().getTableSchema(mainTableName);

rd.setSelectFields(tablescheme.getDisplayFieldIds());

/*RetrieveLimitedRecordsCommand retrieveLimitedRecordsCommand = new RetrieveLimitedRecordsCommand(rep.getConnection());

retrieveLimitedRecordsCommand.setSession(rep.getAuthenticatedUserSession().getSession());

retrieveLimitedRecordsCommand.setResultDefinition(rd);

retrieveLimitedRecordsCommand.setSearch(search);

retrieveLimitedRecordsCommand.execute();*/

RetrieveRecordsByIdCommand recordsByIdCommand = new RetrieveRecordsByIdCommand(rep.getConnection());

recordsByIdCommand.addId(new RecordId(mainTableRecordId));

recordsByIdCommand.setSession(rep.getAuthenticatedUserSession().getSession());

recordsByIdCommand.setResultDefinition(rd);

//recordsByIdCommand.setSearch(search);

recordsByIdCommand.execute();

int totalRecord = recordsByIdCommand.getRecords().getCount();

logMessage("attachBlobToRecord records found: " + totalRecord);

RecordResultSet records=recordsByIdCommand.getRecords();

for(int i=0; i<totalRecord; i++)

{

Record rec = records.getRecord(0);

RecordValue recvalue = readRecordField(rep, mainTableName, fileFieldName, rec.getId().getIdValue());

recvalue.record.setFieldValue(rep.getFieldId(mainTableName, fileFieldName), new LookupValue(blobRecordId));

logMessage("rec.getId().getIdValue()" + rec.getId().getIdValue());

ModifyRecordCommand modifyCommand = new ModifyRecordCommand(rep.getConnection());

modifyCommand.setSession(rep.getAuthenticatedUserSession().getSession());

modifyCommand.setModifyAnyway(true);

//rec.setSource(new LookupValue(new RecordId(blobRecordId)));

modifyCommand.setRecord(rec);

modifyCommand.execute();

}

}

catch (Exception e){

logMessage("attachBlobToRecordMessage:" + e.getMessage());

e.printStackTrace();

}

}

}

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Satish,

I guess some thing going wrong here.

TableSchema tablescheme = rep.getRepositorySchema().getTableSchema(mainTableName);

rd.setSelectFields(tablescheme.getDisplayFieldIds());

you are setting only display fields into ResultDefinition ( rd.setSelectFields(tablescheme.getDisplayFieldIds());)

are you sure that your PDF lookup field from your Main table is displayfield ?

if not you need to set PDF field not just display fields;

correct the code as specified above, and if you still face the same problem , let me know;

regards

Rajasekhar K