MI API
Table of contents
Since: 0.9.0
Context: XtendM3 API
Category: Context Specific —
Description
The MI API allows for reading input parameters and writing output parameters sent into transactions. Supports both single and multiple transactions, custom logic and validation. It can for example be used to abort transaction based on own validation. Also Provides error management.
Features
mi.inData
This method allows to get value from data container and containes In values for Transactions. Contained values are already converted to the proper type. Takes string key as a parameter and returns value associeted with the key.
Example:
private String whlo;
private String itno;
private String whsl;
void inData() {
whlo = mi.inData.get("WHLO").trim();
itno = mi.inData.get("ITNO").trim();
whsl = mi.inData.get("WHSL").trim();
}
mi.outData
This method id used to put value into the data container. Takes key and associeted with it value as parameters, returns previous value.
Example 1:
void outData() {
mi.outData.put("WHLO", "This is WHLO Output#1 for QQS001");
mi.outData.put("ITNO", "This is ITNO Output#2 for QQS002");
mi.write();
}
Example 2:
void outData() {
mi.outData.put("WHLO", String.valueOf(getParameter("NUMB", Double.class).orElse(null)));
mi.write();
}
mi.getDateFormat
This method checks date format and returns it as a string. Possible formats: YMD8, YMD6, MDY6, DMY6, YWD5.
Example:
void getDateFormat() {
if (mi.getDateFormat(date1) == "YMD8"){
return LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
}
}
mi.getDateSeparator
Returns date separator as a char.
Example:
void getDateSeparator () {
char sep = mi.getDateSeparator().toString();
String oldDate = '04-DEC-2012'
String newDate = oldDate.replace("-", sep.toString());
}
mi.getRemainingRecords
Returns the amount of remaining records allowed to be written in current transaction.
Example:
void getRemainingRecords() {
if (mi.getRemainingRecords()>= 2) {
for (int i = 0; i < 3; i++) {
mi.outData.put("WHLS" + WHSL)
mi.write()
}
}
}
mi.hasRemainingRecords
Returns true if there are still any additional records to be written or false if not.
Example:
void hasRemainingRecords() {
if (mi.hasRemainingRecords()){
mi.outData.put("MMRI" + SLDQ)
mi.write()
}
}
mi.getMaxRecords
Returns the maximum amount of possible records to be written as an integer.
Example:
void getMaxRecords() {
String WHSL = mi.in.get("WHSL")
for (int i = 0; i < mi.getMaxRecords(); i++) {
mi.outData.put("WHLS" + WHSL + " " + i)
mi.write()
}
}
mi.write
Writes response from data present in outData. Clears all values in outData.
Example:
void writeRecord() {
mi.outData.put("WHLO","Test")
mi.write()
}
mi.error
Writes error responses with parameters:
- String errorMessage - error message to display (only supports 240 characters)
- String field - field error occurred for (only supports 10 characters)
- String errorCode - code for error which occurred (only supports 2 characters)
Example 1:
boolean validateInput() {
if (!getWarehouse(whlo)) {
mi.error("Warehouse " + whlo + " is invalid");
return false;
} else {
return true;
}
}
Example 2:
boolean validResponsible(String responsible) {
if (responsible.isEmpty()) {
mi.error("Responsible must be entered");
return false;
} else {
return true;
}
}
Considerations and Guidelines
It is not possible to add extra fields to transactions using MI API.