I am using query for dialog
need to get the values of that query
Create a query.
action type menu item
add to controller class
form controller class getting the service class
here in service class we are getting contract class.
here in attribute of contact class we are passing our query
contract class:
/// <summary>
/// Contract class for releasing sales order
/// </summary>
[DataContractAttribute]
class FBHSalesReleaseOrderContract
{
str packedQuery;
[DataMemberAttribute,
AifQueryTypeAttribute('_packedQuery', querystr(FBHSalesAgreementFollowUp))]
/// <summary>
/// Parm method to return and set parameters.
/// </summary>
/// <param name="_packedQuery">
/// </param>
/// <returns>
/// Returnd the parameter passed.
/// </returns>
public str parmQuery(str _packedQuery = packedQuery)
{
packedQuery = _packedQuery;
return packedQuery;
}
/// <summary>
/// Method to return query.
/// </summary>
/// <returns>
/// Returnd the query.
/// </returns>
public Query getQuery()
{
return new Query(SysOperationHelper::base64Decode(packedQuery));
}
/// <summary>
/// Method to set the query.
/// </summary>
/// <param name="_query">
/// </param>
public void setQuery(Query _query)
{
packedQuery = SysOperationHelper::base64Encode(_query.pack());
}
}
Controller class:
/// <summary>
/// Controller class for release order
/// </summary>
class FBHSalesReleaseOrderController extends SysOperationServiceController
{
/// <summary>
/// Construct for calling service class
/// </summary>
/// <param name = "_args">Argument</param>
/// <returns></returns>
public static FBHSalesReleaseOrderController construct(SysOperationExecutionMode _executionMode=SysOperationExecutionMode::Synchronous)
{
FBHSalesReleaseOrderController FBHSalesReleaseOrderController = new FBHSalesReleaseOrderController(classStr(FBHSalesReleaseOrderService),methodStr(FBHSalesReleaseOrderService,process),_executionMode);
return FBHSalesReleaseOrderController;
}
/// <summary>
/// Main method for controller class
/// </summary>
/// <param name = "_args"></param>
public static void main(Args _args)
{
FBHSalesReleaseOrderController FBHSalesReleaseOrderController;
FBHSalesReleaseOrderController = FBHSalesReleaseOrderController::construct();
FBHSalesReleaseOrderController.startOperation();
}
/// <summary>
/// To set the dialog caption
/// </summary>
/// <param name = "_dialogCaption"></param>
/// <returns></returns>
public LabelType parmDialogCaption(LabelType _dialogCaption = "")
{
return "@FBH:FBH50718";
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected boolean canRunInNewSession()
{
boolean ret;
ret = super();
ret = true;
return ret;
}
}
Service class:
/// <summary>
/// Service class for releasing sales order
/// </summary>
class FBHSalesReleaseOrderService
{
/// <summary>
/// Method to run the query and apply validations.
/// </summary>
/// <param name="_FBHSalesReleaseOrderContract">
/// FBHSalesReleaseOrderContract contract class parameter
/// </param>
public void process(FBHSalesReleaseOrderContract _FBHSalesReleaseOrderContract)
{
Query query;
QueryRun queryRun;
query = _FBHSalesReleaseOrderContract.getQuery();
queryRun = new QueryRun(query);
query = queryRun.query();
QueryBuildDataSource qbds = query.dataSourceTable(tableNum(AgreementLine));
QueryFilter filter = query.findQueryFilter(qbds, fieldId2Name(tableNum(AgreementLine), fieldNum(AgreementLine, FBHReleaseDate)));
if (filter == null)
{
filter = query.addQueryFilter(qbds, fieldId2Name(tableNum(AgreementLine), fieldNum(AgreementLine, FBHReleaseDate)));
}
if (filter && filter.value() == "")
{
filter.value(queryValue(DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone())));
}
SalesAgreementHeader salesAgreementHeader;
while(queryRun.next())
{
if (queryRun.changed(tableNum(SalesAgreementHeader)) )
{
salesAgreementHeader = queryRun.get(TableNum(SalesAgreementHeader)) as SalesAgreementHeader;
salesAgreementHeader = SalesAgreementHeader::findAgreementId(SalesAgreementHeader.SalesNumberSequence);
if(( SalesAgreementHeader.LatestLineExpirationDate
&& SalesAgreementHeader.LatestLineExpirationDate
<= DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()))
||!SalesAgreementHeader::hasdeliverySchedule(SalesAgreementHeader))
{
continue;
}
try
{
ttsbegin;
FBHSalesReleaseOrderService::releaseOrderFromAgreement(SalesAgreementHeader,query);
ttscommit;
}
catch(Exception::Error)
{
continue;
}
}
}
}
/// <summary>
/// Release order from agreement
/// </summary>
/// <param name = "salesAgreementHeader">sales agreement from which order is to be released</param>
/// <param name = "_query">passing selected query from dialog</param>
public static void releaseOrderFromAgreement(SalesAgreementHeader salesAgreementHeader,Query _query = new Query())
{
salesCreateReleaseOrderTableTmp salesCreateReleaseOrderTabletmp;
salesCreateReleaseOrderLineTmp salesCreateReleaseOrderLineTmp;
SalesAgreementHeader.Currency = Ledger::accountingCurrency(CompanyInfo::current());
FBHSalesAgreementGenerateReleaseOrder salesAgreementGenerateReleaseOrder
= FBHSalesAgreementGenerateReleaseOrder::construct();
salesAgreementGenerateReleaseOrder.parmSalesAgreementHeader(salesAgreementHeader);
salesAgreementGenerateReleaseOrder.parmisBatch(NoYes::Yes);
salesAgreementGenerateReleaseOrder.parmQuery(_query);
salesAgreementGenerateReleaseOrder.createReleaseOrderTable(salesCreateReleaseOrderTableTmp);
salesAgreementGenerateReleaseOrder.createReleaseOrderLine(salesCreateReleaseOrderLineTmp);
salesAgreementGenerateReleaseOrder.parmReleaseOrderTable(salesCreateReleaseOrderTableTmp);
salesAgreementGenerateReleaseOrder.parmReleaseOrderLine(SalesCreateReleaseOrderLineTmp);
if (salesAgreementGenerateReleaseOrder.check())
{
ttsbegin;
SalesAutoCreate salesAutoCreate = SalesAutoCreate::construct(salesAgreementGenerateReleaseOrder.getreleaseorderline(), null,salesAgreementGenerateReleaseOrder.getreleaseordertable());
salesAutoCreate.create();
ttscommit;
}
}
}
need to get the values of that query
Create a query.
action type menu item
add to controller class
form controller class getting the service class
here in service class we are getting contract class.
here in attribute of contact class we are passing our query
contract class:
/// <summary>
/// Contract class for releasing sales order
/// </summary>
[DataContractAttribute]
class FBHSalesReleaseOrderContract
{
str packedQuery;
[DataMemberAttribute,
AifQueryTypeAttribute('_packedQuery', querystr(FBHSalesAgreementFollowUp))]
/// <summary>
/// Parm method to return and set parameters.
/// </summary>
/// <param name="_packedQuery">
/// </param>
/// <returns>
/// Returnd the parameter passed.
/// </returns>
public str parmQuery(str _packedQuery = packedQuery)
{
packedQuery = _packedQuery;
return packedQuery;
}
/// <summary>
/// Method to return query.
/// </summary>
/// <returns>
/// Returnd the query.
/// </returns>
public Query getQuery()
{
return new Query(SysOperationHelper::base64Decode(packedQuery));
}
/// <summary>
/// Method to set the query.
/// </summary>
/// <param name="_query">
/// </param>
public void setQuery(Query _query)
{
packedQuery = SysOperationHelper::base64Encode(_query.pack());
}
}
Controller class:
/// <summary>
/// Controller class for release order
/// </summary>
class FBHSalesReleaseOrderController extends SysOperationServiceController
{
/// <summary>
/// Construct for calling service class
/// </summary>
/// <param name = "_args">Argument</param>
/// <returns></returns>
public static FBHSalesReleaseOrderController construct(SysOperationExecutionMode _executionMode=SysOperationExecutionMode::Synchronous)
{
FBHSalesReleaseOrderController FBHSalesReleaseOrderController = new FBHSalesReleaseOrderController(classStr(FBHSalesReleaseOrderService),methodStr(FBHSalesReleaseOrderService,process),_executionMode);
return FBHSalesReleaseOrderController;
}
/// <summary>
/// Main method for controller class
/// </summary>
/// <param name = "_args"></param>
public static void main(Args _args)
{
FBHSalesReleaseOrderController FBHSalesReleaseOrderController;
FBHSalesReleaseOrderController = FBHSalesReleaseOrderController::construct();
FBHSalesReleaseOrderController.startOperation();
}
/// <summary>
/// To set the dialog caption
/// </summary>
/// <param name = "_dialogCaption"></param>
/// <returns></returns>
public LabelType parmDialogCaption(LabelType _dialogCaption = "")
{
return "@FBH:FBH50718";
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected boolean canRunInNewSession()
{
boolean ret;
ret = super();
ret = true;
return ret;
}
}
Service class:
/// <summary>
/// Service class for releasing sales order
/// </summary>
class FBHSalesReleaseOrderService
{
/// <summary>
/// Method to run the query and apply validations.
/// </summary>
/// <param name="_FBHSalesReleaseOrderContract">
/// FBHSalesReleaseOrderContract contract class parameter
/// </param>
public void process(FBHSalesReleaseOrderContract _FBHSalesReleaseOrderContract)
{
Query query;
QueryRun queryRun;
query = _FBHSalesReleaseOrderContract.getQuery();
queryRun = new QueryRun(query);
query = queryRun.query();
QueryBuildDataSource qbds = query.dataSourceTable(tableNum(AgreementLine));
QueryFilter filter = query.findQueryFilter(qbds, fieldId2Name(tableNum(AgreementLine), fieldNum(AgreementLine, FBHReleaseDate)));
if (filter == null)
{
filter = query.addQueryFilter(qbds, fieldId2Name(tableNum(AgreementLine), fieldNum(AgreementLine, FBHReleaseDate)));
}
if (filter && filter.value() == "")
{
filter.value(queryValue(DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone())));
}
SalesAgreementHeader salesAgreementHeader;
while(queryRun.next())
{
if (queryRun.changed(tableNum(SalesAgreementHeader)) )
{
salesAgreementHeader = queryRun.get(TableNum(SalesAgreementHeader)) as SalesAgreementHeader;
salesAgreementHeader = SalesAgreementHeader::findAgreementId(SalesAgreementHeader.SalesNumberSequence);
if(( SalesAgreementHeader.LatestLineExpirationDate
&& SalesAgreementHeader.LatestLineExpirationDate
<= DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()))
||!SalesAgreementHeader::hasdeliverySchedule(SalesAgreementHeader))
{
continue;
}
try
{
ttsbegin;
FBHSalesReleaseOrderService::releaseOrderFromAgreement(SalesAgreementHeader,query);
ttscommit;
}
catch(Exception::Error)
{
continue;
}
}
}
}
/// <summary>
/// Release order from agreement
/// </summary>
/// <param name = "salesAgreementHeader">sales agreement from which order is to be released</param>
/// <param name = "_query">passing selected query from dialog</param>
public static void releaseOrderFromAgreement(SalesAgreementHeader salesAgreementHeader,Query _query = new Query())
{
salesCreateReleaseOrderTableTmp salesCreateReleaseOrderTabletmp;
salesCreateReleaseOrderLineTmp salesCreateReleaseOrderLineTmp;
SalesAgreementHeader.Currency = Ledger::accountingCurrency(CompanyInfo::current());
FBHSalesAgreementGenerateReleaseOrder salesAgreementGenerateReleaseOrder
= FBHSalesAgreementGenerateReleaseOrder::construct();
salesAgreementGenerateReleaseOrder.parmSalesAgreementHeader(salesAgreementHeader);
salesAgreementGenerateReleaseOrder.parmisBatch(NoYes::Yes);
salesAgreementGenerateReleaseOrder.parmQuery(_query);
salesAgreementGenerateReleaseOrder.createReleaseOrderTable(salesCreateReleaseOrderTableTmp);
salesAgreementGenerateReleaseOrder.createReleaseOrderLine(salesCreateReleaseOrderLineTmp);
salesAgreementGenerateReleaseOrder.parmReleaseOrderTable(salesCreateReleaseOrderTableTmp);
salesAgreementGenerateReleaseOrder.parmReleaseOrderLine(SalesCreateReleaseOrderLineTmp);
if (salesAgreementGenerateReleaseOrder.check())
{
ttsbegin;
SalesAutoCreate salesAutoCreate = SalesAutoCreate::construct(salesAgreementGenerateReleaseOrder.getreleaseorderline(), null,salesAgreementGenerateReleaseOrder.getreleaseordertable());
salesAutoCreate.create();
ttscommit;
}
}
}