Sunday 5 January 2020

Sysoperation Framework - Query

Contract:
[ DataContractAttribute]
class CheckContract implements SysOperationValidatable
{
NoYes checkProduct, checkProbity, checkTransport;
SalesTable salesTable;
str packedQuery;
[
DataMemberAttribute,
AifQueryTypeAttribute(‘_packedQuery’, ”)//queryStr(SalesTable))
]
public str parmPackedQuery(str _packedQuery = packedQuery)
{
packedQuery = _packedQuery;
return packedQuery;
}
public void initQuery()
{
Query newQuery;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
newQuery = new Query(queryStr(SalesTable));
qbds = newQuery.dataSourceTable(tableNum(SalesTable));
qbr = qbds.addRange(fieldNum(SalesTable, SalesId));
if(this.parmSalesTable().SalesId)
{
qbr.value(this.parmSalesTable().SalesId);
qbr.status(1);//Lock query range
}
this.setQuery(newQuery);
}
public Query getQuery()
{
return
new Query(SysOperationHelper::base64Decode(packedQuery));
}
public void setQuery(Query _query)
{
packedQuery = SysOperationHelper::base64Encode(_query.pack());
}
[
DataMemberAttribute(‘CheckProduct’),
SysOperationLabelAttribute(‘Check product’),
SysOperationDisplayOrderAttribute(‘1’),
SysOperationHelpTextAttribute(literalStr(“If yes, product logic will be executed.”))
]
public NoYes parmCheckProduct(NoYes _checkProduct = checkProduct)
{
checkProduct = _checkProduct;
return checkProductCompilance;
}
[
DataMemberAttribute(‘checkProbity’),
SysOperationLabelAttribute(‘Check probity’),
SysOperationDisplayOrderAttribute(‘2’),
SysOperationHelpTextAttribute(literalStr(“If yes, probity logic will be executed.”))
]
public NoYes parmCheckProbity(NoYes _checkProbity = checkProbity)
{
checkProbity = _checkProbity;
return checkProbity;
}
[
DataMemberAttribute(‘CheckTransport’),
SysOperationLabelAttribute(‘Check transport’),
SysOperationDisplayOrderAttribute(‘3’),
SysOperationHelpTextAttribute(literalStr(“If yes, transportlogic will be executed.”))
]
public NoYes parmCheckTransport(NoYes _checkTransport = checkTransport)
{
checkTransport = _checkTransport;
return checkTransport;
}
public boolean validate()
{
boolean isValid = true;
return isValid;
}
[
DataMemberAttribute(‘SalesOrder’),
SysOperationControlVisibilityAttribute(false),
SysOperationDisplayOrderAttribute(‘4’),
SysOperationHelpTextAttribute(literalStr(“SalesOrder”))
]
public SalesTable parmSalesTable(SalesTable _salesTable = salesTable)
{
salesTable = _salesTable;
return salesTable;
}
}
Controller:
[SysOperationJournaledParametersAttribute(true)]
class checkController extends SysOperationServiceController
{
Common callerRecord;
void new()
{
super();
this.parmClassName(classStr(CheckService));
this.parmMethodName(methodStr(CheckService, process));
this.parmDialogCaption(‘check’);
}
public static void main(Args _args)
{
CheckContract contract;
CheckController controller;
controller = new CheckController();
controller.parmShowDialog(true);
contract = controller.getDataContractObject();
contract.parmSalesTable(SalesTable::findRecId(_args.record().RecId));
contract.initQuery();
controller.startOperation();
}
public LabelType parmDialogCaption(LabelType _dialogCaption = “”)
{
LabelType caption;
caption = “check”;
return caption;
}
private void initFromCaller()
{
SalesTable salesTable;
}
public boolean canGoBatch()
{
return true;
}
public Common parmCallerRecord(Common _callerRecord = callerRecord)
{
callerRecord = _callerRecord;
return callerRecord;
}
/// Refreshes the calling form data source.
protected void refreshCallerRecord()
{
FormDataSource callerDataSource;
if (this.parmCallerRecord() && this.parmCallerRecord().dataSource())
{
callerDataSource = this.parmCallerRecord().dataSource();
callerDataSource.research(true);
}
}
}
Service:
using System.Xml.Linq;
[SRSReportQueryAttribute(queryStr(SalesTable))]
class CheckService extends SysOperationServiceBase
{
static XElement generateXML(Name _jurisdictionId, ItemId _itemId, ItemId _itemIdBOM2, Description _attributeValue)
{
XElement XMLElement =  new XElement(“Check”,
new XElement(“Jurisdiction ID”, _jurisdictionId),
new XElement(“Item Id”, _itemId),
new XElement(“Item Id”, _itemIdBOM2),
new XElement(“Attribute value”,_attributeValue));
return XMLElement;
}
public void process(CheckContract _contract)
{
NoYes checkProduct, checkProbity, checkTransport;
SalesTable callerSalesTable, salesTable;
QueryRun queryRun;
checkProduct = _contract.parmCheckProduct();
checkProbity = _contract.parmCheckProbity();
checkTransport = _contract.parmCheckTransport();
callerSalesTable = _contract.parmSalesTable();
try
{
queryRun = new queryRun(_contract.getQuery());
while(queryRun.next())
{
salesTable = queryRun.get(tableNum(SalesTable));
//logic
}
}
catch (Exception::Error)
{
retry;
}
}

}