on 06-30-2008 4:20 PM
Hi all,
i am able to get the validataions name and id's by using java api. but i am not able to apply that validation to the table by using java api.
please provide some sample code regarding that one
Are you using the ValidateRecordsCommand? It takes a TableId, RecordId array, and ValidationId array.
Edited by: Greg Austin on Jun 30, 2008 11:36 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Austin,
i am using validation record command class only . but when i am using the method setTable Id ,setRecoId method only.
when i am passing validaion id's arry it is showing null pointer exception. i am attaching my code below . plz correct it
RecordResultSet r1 = rs1.getRecords();
com.sap.mdm.data.Record[] recs = rs.getRecords();
//Record[] recs=r1.getRecords();
for(int k=0;k<rs1.getRecords().getCount();k++) {
//00000000000000000000000000000000000000000000000000000000
/****************Validations****************/
RetrieveValidationsCommand retValidation = new RetrieveValidationsCommand(connections);
retValidation.setSession(session);
retValidation.setTableId(maintableId);
try {
retValidation.execute();
}
catch(Exception ev) {
}
ValidationPropertiesResult valip = retValidation.getValidationPropertiesResult();
ValidationProperties[] val = valip.getValidations();
ValidationId[] valID = null;
RecordId[] recordId =null;
System.out.println("Length of val**********:"+val.length);
for(int l=0; l<val.length ;l++ ) {
System.out.println("validation Nmae:"+val[l].getName());
System.out.println("validation Nmae:"+val[l].getId());
valID[l] =val[l].getId();
System.out.println("validation Nmae:***********"+ valID[l] );
recordId[k]=recs[k].getId();
ValidateRecordsCommand valiRecord;
valiRecord = new ValidateRecordsCommand(connections);
valiRecord.setRecordIds(recordId);
valiRecord.setValidationIds(valID) ;
try {
valiRecord.execute();
} catch(Exception ev) {
}
ValidationResult validationResultSet = valiRecord.getValidationResult();
int vp = validationResultSet.getTotalValidationsFailed();
System.out.println("Faild Id:"+vp);
/* for(int p =0;p<faRecod.length;p++)
{
final int fp = faRecod[p].id;
System.out.println("Faild Id:"+fp);
}*/
}
//000000000000000000000000000000000000000000000000000
There are a couple of things I see. I would get rid of the two loops. The ValidateRecordsCommand is made to run multiple validations on multiple records at once. I don't think you need to run this command several times.
At the very top where you get an array of Records what is the rs variable. I believe you want to run the getRecords() method of the RecordResultSet which would be r1 in your example.
I think you already get the RecordId array you want at the top, you already have the TableId, so all you need is one loop to get the ValidationId array. Something like:
RetrieveValidationsCommand retValidation = new RetrieveValidationsCommand(connections);
retValidation.setSession(session);
retValidation.setTableId(maintableId);
try {
retValidation.execute();
}catch(Exception ev) {
}
ValidationPropertiesResult valip = retValidation.getValidationPropertiesResult();
ValidationProperties[] val = valip.getValidations();
ValidationId[] valID = new ValidationId[val.length];
for(int i = 0; i < val.length; i++){
valID<i> = val.getId();
}
So now you have the ValidationId array. So setup the ValidateRecordsCommand.
ValidateRecordsCommand valiRecords = new ValidateRecordsCommand(connections);
valiRecords.setSession(session);
valiRecords.setRecordIds(recs);
valiRecords.setTableId(maintableId);
valiRecords.setValidationIds(valID);
try{
valiRecords.execute();
}catch(Exception e){
//handle error here
}
The reason you are getting a NullPointerException is you never initialize the variable recordId, but you try to assign to it with the line recordId[k]=recs[k].getId();
Ratna,
You can't get a field's value directly from a RecordId. You would have to get it from the Record. At the beginning of the code you posted you get an array of Records from a RecordResultSet. You can get field values from these Records if you put the fields in the ResultDefinition of the Search you ran to get the Records.
I have never tried to create validations with the API, but looking at the Javadocs I don't immediately see anything to create validations.
-Greg
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.