Search This Blog

Tuesday, October 25, 2011

Convert str to Date while importing from XML into AIF

When we are importing the date from xml to AIF we cannot convert that string to date using str2date().
The following function is used to convert from str to date.

Date ConvertXMLStrToDate(str _xmlValue)
{
    System.DateTime                 netDttm;
    str strTransDateTime;
    utcdatetime                     TransDateTime;
    ;
    new  InteropPermission(InteropKind::CLRInterop).assert();
    netDttm = System.DateTime::Parse(_xmlValue);
    TransDateTime=Global::utcDateTime2SystemDateTime(netDttm);
    return dateTimeUtil::date(TransDateTime);
}

Call from job

static void krishh_ConvertXmlStrToDate(Args _args)
{
date datevar;
System.DateTime                 netDttm;
str strTransDateTime;
utcdatetime                     TransDateTime;
EDSA_CreateSalesOrder createsales;
;
createsales=new EDSA_CreateSalesOrder();
strTransDateTime='2011-08-25 00:00:00';
datevar=createsales.ConvertXMLStrToDate(strTransDateTime);
}

Get all Tables from dictionary using x++

static void Krishh_IterateTables(Args _args)
{
    TreeNode            node;
    TreeNode            childNode;
    TreeNodeIterator    nodeIt;
    FilePath            path;
    ;
    path        = @'\Data dictionary\Tables';
    node        = TreeNode::findNode(path);
    nodeIt      = node.AOTiterator();
    childNode   = nodeIt.next();
    while(childNode)
    {
        info( childNode.treeNodeName());
        childNode = nodeIt.next();
    }
}

Monday, October 24, 2011

Extract Message from Exception infolog and Log into the ExceptionTable

Gets the Message from the Exception and Store into table.

public void writeInfoLogData(str ExceptionLogged,InfologData _infologData,str _orderId)
{
       SysExceptionTable               exceptionTable;
    SysInfoLogEnumerator            infoLogEnum;
    SysInfologMessageStruct         infoMessageStruct;
    EDSACRMSyncExceptionLog  CRMSyncLog;
    str  ExceptionMessage;
    ;
    infoLogEnum = SysInfoLogEnumerator::newData(_infologData);
    while(infoLogEnum.moveNext())
    {
        //Extract the message from the string
        infoMessageStruct = SysInfologMessageStruct::construct(infoLogEnum.currentMessage());
        ExceptionMessage +="\n" + infoMessageStruct.message();
    }
    CRMSyncLog.clear();
    CRMSyncLog.initValue();
    CRMSyncLog.ExceptionId=ExceptionLogged;
    CRMSyncLog.ExceptionTxt=ExceptionMessage;
    CRMSyncLog.RefOrderId=_orderId;
    CRMSyncLog.insert();
}

Call from job

static void krishh_LoadMessageFromException(Args _args)
{
    SalesTable salesTable;
    InfologData         infoData;
    AifInfoLog          aifInfoLog;
    container           infologData;
    ;
        infologData = connull();
    try
    {
        aifInfoLog = new AifInfoLog();
        salesTable.clear();
        salesTable.insert();
    }
    catch(Exception::Error)
    {
        infologData = aifInfoLog.getInfoLogData();
        EDSA_CreateSalesOrder::writeInfoLogData('SalesTableCreation',infologData,'10334');
    }
}

Saturday, October 22, 2011

Find mandatory fields in the table

This job is used to find the mandatory fields in the table.

static void Krishh_findMandatory(Args _args)
{
    TableId   tableId = tableNum(SalesTable);
    DictTable dt;
    int       fieldCnt;
    int       i;
    DictField df;
    ;
    dt = new DictTable(tableId);
    fieldCnt = dt.fieldCnt();
    for(i = 1; i <= fieldCnt; i++)
    {
        df = new DictField(tableId, dt.fieldCnt2Id(i));
        if(df.mandatory())
        {
            info("Field '" + df.name() + "' is mandatory.");
        }
    }
}

Call AIF OutBound Service using X++

This job is used to read the sales order based on Sales id and loads into the outboundchannel location.

static void krish_OutboundAifProcess(Args _args)
    {
        AxdSendContext          axdSendContext      = AxdSendContext::construct();
        AifEntityKey            aifEntityKey        = AifEntityKey::construct();
        AIFQueryCriteria   QueryCriteria;
        AifAction               aifAction ;
        AifConstraint           aifConstraint       = new AifConstraint();
        AifConstraintList       aifConstraintList   = new AifConstraintList();
        SalesTable  salesTable;
        AifOutboundProcessingService AifOutboundProcessingService = new AifOutboundProcessingService();
        AifGatewaySendService   AifGatewaySendService = new AifGatewaySendService();
        ;
        aifAction = AifAction::find(AifSendService::getDefaultSendAction(classnum(AIFCRMOrderReturnService),AifSendActionType::SendByKey)) ;
        salesTable = SalesTable::find("10334");
        aifEntityKey.parmTableId(salesTable.TableId);
        aifEntityKey.parmRecId(salesTable.RecId);
        aifEntityKey.parmKeyDataMap(SysDictTable::getKeyData(salesTable));
        axdSendContext.parmXMLDocPurpose(XMLDocPurpose::Original);
        axdSendContext.parmSecurity(false);
        aifConstraint.parmType(AifConstraintType::NoConstraint);
        aifConstraintList.addConstraint(aifConstraint) ;
        AifSendService::submitDefault(classnum(AIFCRMOrderReturnService),
                                        aifEntityKey,
                                        aifConstraintList,
                                        AifSendMode::Sync,
                                        axdSendContext.pack());
        AifOutboundProcessingService.run();
        AifGatewaySendService.run();
    }

Friday, October 14, 2011

Call AIFService File Endpoint

 static void kris_AIFService(Args _args)
    {
        AifGatewayReceiveService    AifGatewayReceiveService;
        AifInboundProcessingService AifInboundProcessingService;
        ;
        AifGatewayReceiveService = new AifGatewayReceiveService();
        AifGatewayReceiveService.run();
        AifInboundProcessingService = new AifInboundProcessingService();
        AifInboundProcessingService.run();
    }

Replace ALL function

This function is used to replace the string in the entire string.

str replaceAll( str s, str findStr, str replStr )
{
    int pos = strscan( s, findStr, 1, strlen( s ) );
    ;
    while( pos > 0 )
    {
        s = strdel( s, pos, strlen( findStr ) );
        s = strins( s, replStr, pos );
        pos = strscan( s, findStr, pos + strlen( replStr ), strlen( s ) );
    }
     return s;
}