How to: Code the Outbound Exchange
standard example:
\Classes\CustPrintOutInvoice\sendAsXML
When the user clicks the Send electronically button, the clicked event calls two methods from the LedgerJournalTable table:
The canXMLBeSent method ensures that an endpoint has been configured for the selected document action. If there is no endpoint configured, the code returns false. Replace the service class with the name of your service class. In this section you will add this method to the table used by the form to which you added the button.
The sendElectronically method gets the entity key for the selected journal, calls the method that retrieves the data, serializes that data into an XML message, and then sends the document to the gateway queue. Replace the service name with the name of your service.
_____________________________________________________________________________
// Use this job to test AIF export, replace " document service class" as per your Entity query.
static void AIFExportTest(Args _args)
{
afmAlsoKnownAs afmAlsoKnownAsObj;
AxdSendContext axdSendContext = AxdSendContext::construct();
AifEntityKey aifEntityKey = AifEntityKey::construct();
Map keyData;
AifConstraint aifConstraint = new AifConstraint() ;
AifConstraintList aifConstraintList = new AifConstraintList();
try
{
while select afmAlsoKnownAsObj
where afmAlsoKnownAsObj.AKAgroupId == '2108' || afmAlsoKnownAsObj.AKAgroupId == '2109'
{
keyData = SysDictTable::getKeyData(afmAlsoKnownAsObj);
aifEntityKey.parmTableId(afmAlsoKnownAsObj.TableId);
aifEntityKey.parmRecId(afmAlsoKnownAsObj.RecId);
aifEntityKey.parmKeyDataMap(keyData);
axdSendContext.parmXMLDocPurpose(xmlDocPurpose::Original);
axdSendContext.parmSecurity(false);
aifConstraint.parmType(AifConstraintType::NoConstraint);
aifConstraintList.addConstraint(aifConstraint);
AifSendService::submitDefault(
classNum(afmAlsoKnownAsService),
aifEntityKey,
aifConstraintList,
AifSendMode::Async,
axdSendContext.pack());
}
new AifOutboundProcessingService().run();
new AifGatewaySendService().run();
}
catch
{
info('error');
}
info('Outbound data processed');
}
-----------
standard example:
\Classes\CustPrintOutInvoice\sendAsXML
When the user clicks the Send electronically button, the clicked event calls two methods from the LedgerJournalTable table:
- canXMLBeSent
- sendElectronically
The canXMLBeSent method ensures that an endpoint has been configured for the selected document action. If there is no endpoint configured, the code returns false. Replace the service class with the name of your service class. In this section you will add this method to the table used by the form to which you added the button.
To add the canXMLBeSent table method
- Press Ctrl+D to open the AOT, expand the Data Dictionary node, expand the Tables node, and then expand the node for the form table.
- Right-click the Methods node, and then click New method.
- In the code editor, copy the following code into the new method.
boolean canXMLBeSent() { boolean ret; AifActionId actionId; AifEndpointList endpointList; AifConstraint aifConstraint = new AifConstraint(); AifConstraintList aifConstraintList = new AifConstraintList(); ; actionId = AifSendService::getDefaultSendAction(classnum([service class]), AifSendActionType::SendByKey); if(actionId) { aifConstraint.parmType(AifConstraintType::NoConstraint); aifConstraintList.addConstraint(aifConstraint); endpointList = AifSendService::getEligibleEndpoints(actionId, aifConstraintList); if(endpointList.getEndpointCount()>0) { ret = true; } } return ret; }
To add code to the sendElectronically table method
- Press Ctrl+D to open the AOT, in the form table, right-click the Methods node, and then click New method.
- In the code editor, copy the following code into the new method.
void sendElectronically(XMLDocPurpose _xMLDocPurpose, AifSendMode _aifSendMode = AifSendMode::Async) { AxdSendContext axdSendContext = AxdSendContext::construct(); AifEntityKey aifEntityKey = AifEntityKey::construct(); Map keyData; AifConstraintList aifConstraintList = new AifConstraintList(); AifConstraint aifConstraint = new AifConstraint(); ; keyData = SysDictTable::getKeyData(this); aifEntityKey.parmTableId(this.TableId); aifEntityKey.parmRecId(this.RecId); aifEntityKey.parmKeyDataMap(keyData); axdSendContext.parmXMLDocPurpose(_xMLDocPurpose); axdSendContext.parmSecurity(false); aifConstraint.parmType(AifConstraintType::NoConstraint) ; aifConstraintList.addConstraint(aifConstraint) ; AifSendService::submitDefault( classnum([service name]), aifEntityKey, aifConstraintList, _aifSendMode, axdSendContext.pack()); }
In this section, you will add code to the clicked events for the SendXMLOriginal and SendXMLDuplicate buttons. The following code uses the table LedgerJournalTable in the example; you will replace the table name with your table name.
To add code to the button clicked event
- In the AOT, expand the Forms node and navigate to the form to which you added the button. Expand the form and navigate to the button. For example, Designs > Design > Group:Group > ButtonGroup:ButtonGroup. > MenuButton:SendXMLMenu > MenutItemButton:SendXMOriginal.
- Right-click the Methods node, click Override Method, and then select clicked.
- In the code editor, enter the following code in the clicked event.
void clicked() { LedgerJournalTable ledgerJournalTableLocal; ; for (ledgerJournalTableLocal = LedgerJournalTable_ds.getFirst(true) ? LedgerJournalTable_ds.getFirst(true) : LedgerJournalTable; ledgerJournalTableLocal; ledgerJournalTableLocal = LedgerJournalTable_ds.getNext()) // Check to see if document can be sent. if (ledgerJournalTableLocal.canXMLBeSent()) { // Send the document. ledgerJournalTableLocal.sendElectronically(XMLDocPurpose::Original); } else { warning (strfmt("@SYS72175")); // TODO Add a ledger journal specific error message to the // label file. // warning (strfmt("@SYSnnnnn",ledgerJournalTableLocal.JournalNum)); } super(); }
- Repeat steps 1 through 3 for the MenuItemButton:SendXMLDuplicate control.
- In the clicked event of the MenutItemButton:SendXMLDuplicate button control, change XMLDocPurpose::Original to XMLDocPurpose::Duplicate.
// Use this job to test AIF export, replace " document service class" as per your Entity query.
static void AIFExportTest(Args _args)
{
afmAlsoKnownAs afmAlsoKnownAsObj;
AxdSendContext axdSendContext = AxdSendContext::construct();
AifEntityKey aifEntityKey = AifEntityKey::construct();
Map keyData;
AifConstraint aifConstraint = new AifConstraint() ;
AifConstraintList aifConstraintList = new AifConstraintList();
try
{
while select afmAlsoKnownAsObj
where afmAlsoKnownAsObj.AKAgroupId == '2108' || afmAlsoKnownAsObj.AKAgroupId == '2109'
{
keyData = SysDictTable::getKeyData(afmAlsoKnownAsObj);
aifEntityKey.parmTableId(afmAlsoKnownAsObj.TableId);
aifEntityKey.parmRecId(afmAlsoKnownAsObj.RecId);
aifEntityKey.parmKeyDataMap(keyData);
axdSendContext.parmXMLDocPurpose(xmlDocPurpose::Original);
axdSendContext.parmSecurity(false);
aifConstraint.parmType(AifConstraintType::NoConstraint);
aifConstraintList.addConstraint(aifConstraint);
AifSendService::submitDefault(
classNum(afmAlsoKnownAsService),
aifEntityKey,
aifConstraintList,
AifSendMode::Async,
axdSendContext.pack());
}
new AifOutboundProcessingService().run();
new AifGatewaySendService().run();
}
catch
{
info('error');
}
info('Outbound data processed');
}
- For more info : https://msdn.microsoft.com/en-US/library/bb530214(v=ax.50).aspx
Comments
Post a Comment