on 12-03-2007 9:24 AM
I have a qualified table with phone numbers, but how do I use API 2 to create a new value for a record?
It would be great with code examples.
I have found a solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry that I have not anwserd before now.
I'm fairly new to work with the MDM API, so baer with me if this is not the best way to do it. If anyone has ideas to do it a better way please let me know.
This is the way I solved it hope you can use it.
- First I search my qualifer table for the recordId that fits to my non-qualifer.
- Then I create a QualifiedLinkValue with the recordId.
- Then I search for the recordId for the qualifer-field in my main table
- I add the qualifer-fields value for the qualifer tabler with setQualifierFieldValue
- Then I save the record.
IPrivateCreateView.IContextElement element = wdContext.currentContextElement();
try {
//This is my qualified table
TableId tableQualifiedId = repository.getTableId("Phone_Numbers");
//This is the non-qualifier field in the table
FieldId fieldIsStandardId = repository.getFieldId("Phone_Numbers", "Is_Standard_Phone_Number");
// specify the result definition (what to retrieve);
ResultDefinition rd = new ResultDefinition(tableQualifiedId);
rd.addSelectField(fieldIsStandardId);
// select all records
Search search = new Search(tableQualifiedId);
FieldSearchDimension searchDim = new FieldSearchDimension(fieldIsStandardId);
BooleanSearchConstraint booleanConstraint = new BooleanSearchConstraint(true);
search.addSearchItem(searchDim, booleanConstraint);
// retrieve the records
RetrieveLimitedRecordsCommand limitingQCommand = new RetrieveLimitedRecordsCommand(repository.getConnection());
limitingQCommand.setSession(repository.getAuthenticatedUserSession());
limitingQCommand.setResultDefinition(rd);
limitingQCommand.setSearch(search);
limitingQCommand.execute();
RecordResultSet rrs = limitingQCommand.getRecords();
Record r = rrs.getRecord(0);
RecordId rId = r.getId();
QualifiedLinkValue linkValue = new QualifiedLinkValue(rId);
QualifiedLookupValue LookupValue = new QualifiedLookupValue();
int link = LookupValue.createQualifiedLink(linkValue);
TableId tableMainId = repository.getTableId("Business_Partners");
TableId tablePhone_NumbersId = repository.getTableId("Phone_Numbers");
//Main table
FieldId fieldMainPhone_NumberId = repository.getFieldId("Business_Partners", "Phone_Number");
//Lookup table Phone_Numbers
FieldId fieldQPhone_NumbersCountryId = repository.getFieldId("Phone_Numbers", "Country");
FieldId fieldQPhone_NumbersExtensionId = repository.getFieldId("Phone_Numbers", "Extension");
FieldId fieldQPhone_NumbersNumberId = repository.getFieldId("Phone_Numbers", "Number");
FieldId fieldQPhone_NumbersPhone_Number_TypeId = repository.getFieldId("Phone_Numbers", "Phone_Number_Type");
// specify the result definition (what to retrieve);
//Main
ResultDefinition rdMain = new ResultDefinition(tableMainId);
rdMain.addSelectField(fieldMainPhone_NumberId);
// retrieve the records
RetrieveRecordsByIdCommand limitingCommand = new RetrieveRecordsByIdCommand(repository.getConnection());
limitingCommand.setSession(repository.getAuthenticatedUserSession());
limitingCommand.setResultDefinition(rdMain);
limitingCommand.addId(element.getRecordId());
limitingCommand.execute();
rrs = limitingCommand.getRecords();
ModifyRecordCommand recordCommand = new ModifyRecordCommand(repository.getConnection());
r = rrs.getRecord(0);
if (element.getPhoneExtension() == null)
element.setPhoneExtension("");
if (element.getPhoneNumber() == null)
element.setPhoneNumber("");
LookupValue.setQualifierFieldValue(0, fieldQPhone_NumbersCountryId, new LookupValue(new RecordId(element.getCountry())));
LookupValue.setQualifierFieldValue(0, fieldQPhone_NumbersExtensionId, new StringValue(element.getPhoneExtension()));
LookupValue.setQualifierFieldValue(0, fieldQPhone_NumbersNumberId, new StringValue element.getPhoneNumber()));
LookupValue.setQualifierFieldValue(0, fieldQPhone_NumbersPhone_Number_TypeId, new LookupValue(new RecordId(element.getPhoneType())));
r.setFieldValue(fieldMainPhone_NumberId, LookupValue);
recordCommand.setRecord(r);
recordCommand.setSession(repository.getAuthenticatedUserSession());
ValidateNewRecordValuesCommand validateCommand = new ValidateNewRecordValuesCommand(repository.getConnection());
validateCommand.setSession(repository.getAuthenticatedUserSession());
validateCommand.setRecord(r);
validateCommand.setTableId(tableMainId);
validateCommand.execute();
ValidationResult result = validateCommand.getValidationResult();
RecordId[] ValidationRecordId = result.getRecordIds();
ValidationProperties[] properties = result.getFailedValidations(ValidationRecordId[0]);
if (properties.length > 0) {
element.setStatusBoolean(false);
ValidationProperties property = properties[0];
element.setStatusText(property.getMessage().get());
}
if (element.getStatusBoolean()) {
recordCommand.execute();
}
} catch (Exception e) {
element.setStatusBoolean(false);
element.setStatusText("ERROR: SavePhoneNumberQulifiedFields| " + e.getMessage());
return;
}
User | Count |
---|---|
84 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.