static void AifSample_CustomerService(Args _args)
{
CustCustomerService customerService; // Customer Service class
CustCustomer customer; // Customer Document object
CustCustomer customerRead; // Customer Document object
CustCustomer_CustTable custTable; // CustTable data object
CustCustomer_CustTable custTableRead; // CustTable data object
AifEntityKeyList entityKeyList; // Entity key list
AifEntityKeyList entityKeyListFind; // Entity key list
AifQueryCriteria queryCriteria;
AifCriteriaElement criteriaElement;
AccountNum accountNum;
Name name;
;
// Create the service instance
customerService = CustCustomerService::construct();
// Create the Customer document object
customer = new CustCustomer();
customer.createCustTable(); // Create the CustTable list
custTable = customer.parmCustTable().addNew(); // Add CustTable instance to CustTable list
// Initialize the CustTable instance
// custTable.parmName("Cust01");
custTable.parmAccountNum("22220002");
custTable.parmCustGroup("10");
custTable.parmCurrency("USD");
custTable.parmPartyType(DirPartyType::Organization);
// Create Customer
entityKeyList = customerService.create(customer);
accountNum = entityKeyList.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(CustTable, accountnum));
info(strfmt("Created customer: Account Number: %1.", accountNum));
//Creating another Customer
entityKeyList = customerService.create(customer);
accountNum = entityKeyList.getEntityKey(2).parmKeyDataMap().lookup(FieldNum(Custtable,accountNum));
info(strfmt("Created another Customer : Account Number : %1. ",accountNum));
// Read Customer using returned entity key
customerRead = customerService.read(entityKeyList);
custTableRead = customerRead.parmCustTable().get_Item(0);
info(strfmt("Read customer: Account Number: %1, Name: %2.", custTableRead.parmAccountNum(), custTableRead.parmName()));
// Update Customer
custTableRead.parmName(custTableRead.parmName() + ": Updated Name");
customerService.update(entityKeyList, customerRead);
info (strfmt("Updated Customer: Account Number: %1.", custTableRead.parmAccountNum()));
// Call Read to check update
customer = customerService.read(entityKeyList);
custTable = customerRead.parmCustTable().get_Item(0);
info(strfmt("Read updated customer: Account Number: %1, Name: %2.", custTable.parmAccountNum(), custTable.parmName()));
// Call FindKeys to find entity keys of matching customer entity keys
queryCriteria = new AifQueryCriteria();
criteriaElement = AifCriteriaElement::newCriteriaElement('CustTable', 'CustGroup', AifCriteriaOperator::Equal, '10');
queryCriteria.addCriteriaElement(criteriaElement);
entityKeyListFind = customerService.findKeys(queryCriteria);
info(strfmt("Find customer keys: Result count: %1", entityKeyListFind.getEntityKeyCount()));
// Call Find to find matching customers
queryCriteria = new AifQueryCriteria();
criteriaElement = AifCriteriaElement::newCriteriaElement('CustTable', 'CustGroup', AifCriteriaOperator::Equal, '10');
queryCriteria.addCriteriaElement(criteriaElement);
customerRead = customerService.find(queryCriteria);
info(strfmt("Find customer: Result count: %1", customerRead.existsCustTable()?customerRead.parmCustTable().get_Count():0));
info("TO DO: To test delete, uncomment delete code in the job.");
// TODO: UNCOMMENT TO DELETE CUSTOMER
/*
// calling deleting customer
customerService.delete(entityKeyList);
info(strfmt("Deleted customer: Account Number: %1.", accountNum));
*/
pause;
}
{
CustCustomerService customerService; // Customer Service class
CustCustomer customer; // Customer Document object
CustCustomer customerRead; // Customer Document object
CustCustomer_CustTable custTable; // CustTable data object
CustCustomer_CustTable custTableRead; // CustTable data object
AifEntityKeyList entityKeyList; // Entity key list
AifEntityKeyList entityKeyListFind; // Entity key list
AifQueryCriteria queryCriteria;
AifCriteriaElement criteriaElement;
AccountNum accountNum;
Name name;
;
// Create the service instance
customerService = CustCustomerService::construct();
// Create the Customer document object
customer = new CustCustomer();
customer.createCustTable(); // Create the CustTable list
custTable = customer.parmCustTable().addNew(); // Add CustTable instance to CustTable list
// Initialize the CustTable instance
// custTable.parmName("Cust01");
custTable.parmAccountNum("22220002");
custTable.parmCustGroup("10");
custTable.parmCurrency("USD");
custTable.parmPartyType(DirPartyType::Organization);
// Create Customer
entityKeyList = customerService.create(customer);
accountNum = entityKeyList.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(CustTable, accountnum));
info(strfmt("Created customer: Account Number: %1.", accountNum));
//Creating another Customer
entityKeyList = customerService.create(customer);
accountNum = entityKeyList.getEntityKey(2).parmKeyDataMap().lookup(FieldNum(Custtable,accountNum));
info(strfmt("Created another Customer : Account Number : %1. ",accountNum));
// Read Customer using returned entity key
customerRead = customerService.read(entityKeyList);
custTableRead = customerRead.parmCustTable().get_Item(0);
info(strfmt("Read customer: Account Number: %1, Name: %2.", custTableRead.parmAccountNum(), custTableRead.parmName()));
// Update Customer
custTableRead.parmName(custTableRead.parmName() + ": Updated Name");
customerService.update(entityKeyList, customerRead);
info (strfmt("Updated Customer: Account Number: %1.", custTableRead.parmAccountNum()));
// Call Read to check update
customer = customerService.read(entityKeyList);
custTable = customerRead.parmCustTable().get_Item(0);
info(strfmt("Read updated customer: Account Number: %1, Name: %2.", custTable.parmAccountNum(), custTable.parmName()));
// Call FindKeys to find entity keys of matching customer entity keys
queryCriteria = new AifQueryCriteria();
criteriaElement = AifCriteriaElement::newCriteriaElement('CustTable', 'CustGroup', AifCriteriaOperator::Equal, '10');
queryCriteria.addCriteriaElement(criteriaElement);
entityKeyListFind = customerService.findKeys(queryCriteria);
info(strfmt("Find customer keys: Result count: %1", entityKeyListFind.getEntityKeyCount()));
// Call Find to find matching customers
queryCriteria = new AifQueryCriteria();
criteriaElement = AifCriteriaElement::newCriteriaElement('CustTable', 'CustGroup', AifCriteriaOperator::Equal, '10');
queryCriteria.addCriteriaElement(criteriaElement);
customerRead = customerService.find(queryCriteria);
info(strfmt("Find customer: Result count: %1", customerRead.existsCustTable()?customerRead.parmCustTable().get_Count():0));
info("TO DO: To test delete, uncomment delete code in the job.");
// TODO: UNCOMMENT TO DELETE CUSTOMER
/*
// calling deleting customer
customerService.delete(entityKeyList);
info(strfmt("Deleted customer: Account Number: %1.", accountNum));
*/
pause;
}
No comments:
Post a Comment