Jump to content

How to get the reference of another table from the context in EBX


Santanu Chakraborty

Recommended Posts

Hi,

 

Hi,

I am new to EBX. Below is my problem statement.

I have a Custom Form Pane. The data model is as followes, There is a Customer Table An AddressGroup table and a Address Table. The AddressGroup is the bridging table where CustomerId and AddressID are stored and one Address ID can be linked to Multiple Customers. In the AddressGroupFormPane java class,I have all the customer Ids for the supplied addressId as parameter. Now with this List of Customers IDs, I need to check the relationship between the Customers in CustomerRelationship table. How can I get into the CustomerRelationship table from this Java Class where thecurrent table isAddressGroup. The Code is as below.

 

try {

 

Adaptation dataSet = aContext.getCurrentTable().getContainerAdaptation();

AdaptationTable addressGroupTable= dataSet.getTable(_AddressGroup.getPathInSchema());

String predicate = __AddressGroup._AddressId.format() + "="+ XPathExpressionHelper.encodeLiteralStringWithDelimiters(addressId);

RequestResult addressGroupTableResultSet= addressGroupTable.createRequestResult(predicate);

 

if (addressGroupTableResultSet!= null) {

Adaptation addressGroup;

String customerID = "";

List listOfCustomersHavingSameAddress = new ArrayList();

 

while ((addressGroup= addressGroupTableResultSet.nextAdaptation()) != null) {

customerID = addressGroup.getString(_AddressGroup._CustomerId);

listOfCustomersHavingSameAddress.add(customerID);

}

 

Adaptation customerRelationshipDataSet = aContext.get()

How to get thecustomerRelationshipDataSet from here since we are at AddressGroup Table

Gret to have some code snippet or suggestions. Thanks.

Link to comment
Share on other sites

Okay so from what I understood these are your configurations.

Customer Table(CustomerID_PK)

Address(AddessID_PK)

AddressGroup(AddressGroupID_PK ,CustomerID_FK, AddressID_FK) - AddressID_FK:CustomerID_FK(1:n)

Now when you are in Context of AddressGroup java class, you want to access CustomerRelationshipTable

Here is how you can do it

//You first need to get Repository

Repository rep = context.getAdapatationhome().getRepository();

//Now in this repository, you can get any dsp, dst, table, record

//Since I am not aware of the dsp, dst name I am calling them as DSP_CR , DST_CR , table is CustomerRelationshipTable

//Get Dataspce

final AdaptationHome dsp = rep.lookupHome(HomeKey.forBranchName("DSP_CR"))

 

//Get Dataset

final Adaptation dst = dsp.findAdaptationOrNull(AdaptationName.forName("DST_CR"))

 

//Get Table

 

AdaptationTable customerRelationShipTable = dst.getTable(Path.parse("Path to Customer Relationship table"))

 

//Now once you have the table, there are different ways to get table record ( by creating a Request on table , by doing a search based on xpath).

1. Use loop to iterate in customerRelationShipTable, read each record and get the relevant values.

2. create a customerRelationShipTable.lookupFirstRecordMatchingPredicate("./paramName="+XPathExpressionHelper.encodeLiteralStringWithDelimiters(value.trim()));

Here : (a.)paramName is the column path (will be your path for CustomerID in customerRelationShipTable)

(b)value is the column value (will be customerID(index), since you have a list of customerIds))

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...