Showing posts with label Outbound. Show all posts
Showing posts with label Outbound. Show all posts

Wednesday, August 10, 2016

Calling an external RESTful Web Service from X++

With the following Job you can consume an External RESTful Web Service:
static void ConsumingRestService(Args _args)
{
    str destinationUrl = 'http://<server>/<service>', requestXml, responseXml;
    System.Net.HttpWebRequest       request;
    System.Net.HttpWebResponse      response;
    CLRObject                       clrObj;
    System.Byte[]                   bytes;
    System.Text.Encoding            utf8;
    System.IO.Stream                requestStream, responseStream;
    System.IO.StreamReader          streamReader;
    System.Exception                ex;

    requestXml = ""
        +"<XML>"
        +"</XML>";

    try
    {
        clrObj = System.Net.WebRequest::Create(destinationUrl);
        request = clrObj;

        utf8 = System.Text.Encoding::get_UTF8();
        bytes = utf8.GetBytes(requestXml);

        request.set_ContentType("text/xml; encoding='utf-8'");
        request.set_ContentLength(bytes.get_Length());
        request.set_Method("POST");

        requestStream = request.GetRequestStream();
        requestStream.Write(bytes, 0, bytes.get_Length());

        response = request.GetResponse();

        responseStream = response.GetResponseStream();
        streamReader = new System.IO.StreamReader(responseStream);
        responseXml = streamReader.ReadToEnd();

        info(responseXml);
    }
    catch (Exception::CLRError)
    {
        //bp deviation documented
        ex = CLRInterop::getLastException().GetBaseException();
        error(ex.get_Message());
    }


    requestStream.Close();
    streamReader.Close();
    responseStream.Close();
    response.Close();

}

Tuesday, May 3, 2016

Send via AIF multiple records to outbound file

If you have a requirement to send more than one record per XML as an outbound, then have a look on the following job:
static void AifSendCustomerFromQuery(Args _args)
{
    AxdSendContext                  axdSendContext      = AxdSendContext::construct();
    AifAction                       aifAction;
    AifConstraint                   aifConstraint       = new AifConstraint();
    AifConstraintList               aifConstraintList   = new AifConstraintList();
    AifOutboundProcessingService    aifOutboundProcessingService = new AifOutboundProcessingService();
    AifGatewaySendService           aifGatewaySendService = new AifGatewaySendService();
    AifActionId                     actionId;
    AifEndpointList                 endpointList;
    Query                           query;
    QueryBuildDataSource            queryBuildDataSource;
    ;

    query = new Query(queryStr(AxdCustomer));
    AxdSend::removeChildDs(query);
    queryBuildDataSource = query.dataSourceTable(tablenum(CustTable));
    queryBuildDataSource.addRange(fieldnum(CustTable, RecId));
    queryBuildDataSource.rangeField(fieldnum(CustTable, RecId)).value(strfmt('5637144577..5637144587'));

    aifAction = AifAction::find(AifSendService::getDefaultSendAction(
                                                        classnum(CustCustomerService), 
                                                        AifSendActionType::SendByQuery));

    axdSendContext.parmXMLDocPurpose(XMLDocPurpose::Original);
    axdSendContext.parmSecurity(false);

    aifConstraint.parmType(AifConstraintType::NoConstraint);
    aifConstraintList.addConstraint(aifConstraint) ;

    endPointList = AifSendService::getEligibleEndpoints(aifAction.ActionId,aifConstraintList);

    AifSendService::submitFromQuery(aifAction.ActionId, endpointList, query, AifSendMode::Sync);

    AifGatewaySendService.run();
    AifOutboundProcessingService.run();
}

Tuesday, April 19, 2016

Run AIF import and export manually

Here is a job to run import and export manually, so you don’t have to wait for the batch jobs:
static void AIFImportExport(Args _args)
{
    // Inbound (import)
    new AifGatewayReceiveService().run();
    new AifInboundProcessingService().run();

    // Outbound (export)
    new AifOutboundProcessingService().run();
    new AifGatewaySendService().run();

    info("AIF import/export done");
}