Mar 23, 2015

Syntax of Try {} catch {} for updation in X++

void clicked()
{

#OCCRetryCount   

#task;  

super();

try

     // logic
}
catch (Exception::Deadlock)

{
      retry;

}
catch (Exception::UpdateConflict)

{
       if (appl.ttsLevel() == 0)

      {
           if (xSession::currentRetryCount() >= #RetryNum)

          {
                throw Exception::UpdateConflictNotRecovered;

          }
      else

     {
           retry;

     }
}
else

{
     throw Exception::UpdateConflict;

}
}
catch (Exception::Error)

{
       throw error("Label");

}
    Table_ds.research();

}

Mar 10, 2015

How to get the query range values through X++ code

static void testQuery(Args _args)
{
Query q;
QueryRun qr;
QueryBuildRange qbr;
str s;
custTrans custTran;
int cnt, i;
queryFilter queryFilter;
;

q = new Query(queryStr(CustOpenInvoicesListPage)); // This is AOT query

qr = new QueryRun(q);

qr.prompt(); // This prompt's the dialog

cnt = qr.query().dataSourceTable(tablenum(custTrans)).rangeCount();

for (i=1 ; i<=cnt; i++)
{
qbr = qr.query().dataSourceTable(tablenum(custTrans)).range(i);
info(strfmt("Field added in Range %1, Range value %2",qbr.AOTname(),qbr.value()));
}

while(qr.next())
{
custTran = qr.get(tableNum(custTrans));
info(strFmt("%1 ---- %2 ",custTran.AccountNum,custTran.TransType));
}
}

Mar 9, 2015

How to get integers from X++ string value

static void intCheck(Args _args)
{
#define.lineIncrement(1)
int64 lineConfirm;
str _text;
str _lineConfirm = 'ECM-00451';

lineConfirm = str2Int64(strKeep(_lineConfirm, "0123456789"));

_text = strRem(_lineConfirm, strFmt("%1",lineConfirm));

lineConfirm = lineConfirm+#lineIncrement;
_lineConfirm = _text+ strFmt("%1",lineConfirm);

info(strFmt("%1",_lineConfirm));
}

Mar 4, 2015

How to use "OR" in X++ Query ..

static void projTableJobUsingQuery(Args _args)
{
    Query                   query;
    QueryBuildDataSource    qb, qb1;
    QueryBuildRange         qbr, qbr1;
    QueryRun                qr;
    SalesTable              salesTableLocal;
str salesid1, salesid2;
    str                     custAccountVal = "0000000015";
str                     invoiceAccountVal = "0000000025";
    ;
salesid1 = "ECM-20000091";
salesid2 = "ECM-20000094";
    query = new Query();
    qb = query.addDataSource(tablenum(Salestable));
qb.addRange(fieldnum(Salestable, SalesId)).value(queryRange(salesId1,SalesId2));
    qbr = qb.addRange(fieldnum(Salestable, CustAccount));

// Here the OR condition is implemented.  
    qbr.value(strfmt('((%1.%2 == "%4") || (%1.%3 == "%5"))',
                qb.name(),
                fieldstr(Salestable, CustAccount),
                fieldstr(Salestable, InvoiceAccount),custAccountVal,invoiceAccountVal));

    qr = new QueryRun(query);
    while (qr.next())
    {
        salesTableLocal = qr.get(tablenum(SalesTable));
        info(salesTableLocal.SalesId);
    }

  
}