Wednesday, December 31, 2014

SSRS Report to Save As Word in AX

// SSRS Report to Save As Word in AX

static void ReportToWord(Args _args)
{
    SrsReportRun srsReportRun;
    srsReportRun = new SrsReportRun("CustListReport.Report");
    srsReportRun.init();
    srsReportRun.reportCaption("CustListReport.Report");
    //srsReportRun.reportParameter("TruckTransDS_JournalId").value("000161_070");
    srsReportRun.showDialog(false);
    srsReportRun.printDestinationSettings().printMediumType(SRSPrintMediumType::File);
    //srsReportRun.printDestinationSettings().fileFormat(SRSReportFileFormat::HTML4_0);
    srsReportRun.printDestinationSettings().overwriteFile(true);
    srsReportRun.printDestinationSettings().fileName("C:\\InventTruckTransactionReport1.doc");

    if( srsReportRun )
    {
        srsReportRun.executeReport();
    }
}

Numerals to Txt as only in output ax 2012 Global class

// Numerals to Txt as only in output ax 2012 Global class

static TempStr numeralsToTxtOnly(real _num)
{
    int     numOfPennies = (decRound(frac(_num), 2) * 100) mod 100;
    real    test         = _num - frac(_num);

    int64   numOfTenths;
    str 20  ones[19], tenths[9], hundreds, thousands, millions, billions, trillions;

    int64   temp;
    str 200 returntxt;
    int64   testLoc;

    real modOperator(real a1, real a2)
    {
    int tmpi;
    real tmp1, tmp2;
    tmp1 = a1 / a2;
    tmpi = real2int(tmp1);
    tmp2 = tmpi;
    return (tmp1 - tmp2)*a2;
    }

    real checkPower(real  _test, int64 _power)
    {
        int64   numOfPower;

        if (_test >= _power)
        {
            testLoc = real2double(_test);
            numOfPower = testLoc div _power;
            if (numOfPower >= 100)
            {
                temp = numOfPower div 100;
                returntxt = returntxt + ' ' + ones[temp] + ' ' + hundreds;
                numOfPower = numOfPower mod 100;
            }
            if (numOfPower >= 20)
            {
                temp = numOfPower div 10;
                returntxt = returntxt + ' ' + tenths[temp];
                numOfPower = numOfPower mod 10;
            }
            if (numOfPower >= 1)
            {
                returntxt = returntxt + ' ' + ones[numOfPower];
                numOfPower = numOfPower mod 10;
            }
            switch(_power)
            {
                case 1000000000000 :
                    returntxt = returntxt + ' ' + trillions;
                    _test = modOperator(_test, 1000000000000.00);
                    break;
                case 1000000000 :
                    returntxt = returntxt + ' ' + billions;
                    _test = modOperator(_test, 1000000000);
                    break;
                case 1000000 :
                    returntxt = returntxt + ' ' + millions;
                    _test = modOperator(_test, 1000000);
                    break;
                case 1000 :
                    returntxt = returntxt + ' ' + thousands;
                    _test = modOperator(_test, 1000);
                    break;
                case 100 :
                    returntxt = returntxt + ' ' + hundreds;
                    _test = modOperator(_test, 100);
                    break;
            }
        }
        return _test;
    }

    #Define.text_1('One')
    #Define.text_2('Two')
    #Define.text_3('Three')
    #Define.text_4('Four')
    #Define.text_5('Five')
    #Define.text_6('Six')
    #Define.text_7('Seven')
    #Define.text_8('Eight')
    #Define.text_9('Nine')
    #Define.text_10('Ten')
    #Define.text_11('Eleven')
    #Define.text_12('Twelve')
    #Define.text_13('Thirteen')
    #Define.text_14('Fourteen')
    #Define.text_15('Fifteen')
    #Define.text_16('Sixteen')
    #Define.text_17('Seventeen')
    #Define.text_18('Eighteen')
    #Define.text_19('Nineteen')
    #Define.text_20('Twenty')
    #Define.text_30('Thirty')
    #Define.text_40('Forty')
    #Define.text_50('Fifty')
    #Define.text_60('Sixty')
    #Define.text_70('Seventy')
    #Define.text_80('Eighty')
    #Define.text_90('Ninety')
    #Define.text_100('Hundred')
    #Define.text_1000('Thousand')
    #Define.text_1000000('Million')
    #Define.text_1000000000('Billion')
    #Define.text_1000000000000('Trillion')
    #Define.text_and('and')

    ones[1] = #text_1;
    ones[2] = #text_2;
    ones[3] = #text_3;
    ones[4] = #text_4;
    ones[5] = #text_5;
    ones[6] = #text_6;
    ones[7] = #text_7;
    ones[8] = #text_8;
    ones[9] = #text_9;
    ones[10] = #text_10;
    ones[11] = #text_11;
    ones[12] = #text_12;
    ones[13] = #text_13;
    ones[14] = #text_14;
    ones[15] = #text_15;
    ones[16] = #text_16;
    ones[17] = #text_17;
    ones[18] = #text_18;
    ones[19] = #text_19;

    tenths[1] = 'Not used';
    tenths[2] = #text_20;
    tenths[3] = #text_30;
    tenths[4] = #text_40;
    tenths[5] = #text_50;
    tenths[6] = #text_60;
    tenths[7] = #text_70;
    tenths[8] = #text_80;
    tenths[9] = #text_90;

    hundreds    = #text_100;
    thousands   = #text_1000;
    millions    = #text_1000000;
    billions    = #text_1000000000;
    trillions   = #text_1000000000000;


    test = checkPower(test, 1000000000000);
    test = checkPower(test, 1000000000);
    test = checkPower(test, 1000000);
    test = checkPower(test, 1000);
    test = checkPower(test, 100);

    if (test >= 20)
    {
        testLoc = real2double(test);
        numOfTenths = testLoc div 10;
        returntxt = returntxt + ' ' + tenths[numofTenths];
        numOfTenths = numOfTenths mod 10;
        test = real2int(test) mod 10;
    }
    if (test >= 1)
    {
        numOfTenths = real2int(test);
        returntxt = returntxt + ' ' + ones[numOfTenths];
    }

    if (numOfPennies)
    {
       // returntxt = '***' + returntxt + ' ' + "@SYS5534" + ' ' + num2str(numOfPennies,0,0,0,0) + '/100';
        returntxt = returntxt + ' ' + "@SYS5534" + ' ' + num2str(numOfPennies,0,0,0,0) + '/100'+ ' Only';
        //returntxt = returntxt + ' ' + #text_and + ' ' + NumtoRupees::numtoRupees(numOfPennies,'SAR');
    }
    else
    {
        returntxt = returntxt + ' Only';// + #text_and + ' ' + '00/100';
        //returntxt = returntxt + ' Only';// + #text_and + ' ' + '00/100';
    }

    return returntxt;
}

Row number in Row Matrix SSRS Report in ax 2012

// Row number in Row Matrix SSRS Report in ax 2012

=Runningvalue(Fields!GroupColumn1Name.Value,countdistinct,"MatrixName")

Sunday, November 23, 2014

Encrypt and Decrypt String in Ax 2012 (Using Base64 string)

//Encrypt and Decrypt in C#
Reference Link: http://www.obviex.com/samples/encryption.aspx

https://stackoverflow.com/questions/10168240/encrypting-decrypting-a-string-in-c-sharp

// Encrypt and Decrypt String in Ax 2012

// Job

static void EncryptDecrypt(Args _args)
{
    San_AdBaseCryptography   crypto = new San_AdBaseCryptography();
    str  inputText = "pos.user123";
    str     enStr,deStr;
    ;
    enStr =crypto.encrypt(inputText);
    deStr = crypto.decrypt(enStr);

    info(inputText);
    info(enStr);
    info(deStr);
}

//Class

// New Class --> San_AdBaseCryptography
public class San_AdBaseCryptography
{
    #define.fixedPassPhrase('Pas5pr@se')
    #define.fixedSaltValue('s@1tValue')
    #define.fixedPasswordIterations(2)
    #define.fixedInitVector('@1B2c3D4e5F6g7H8')
    #define.fixedKeySize(32)

    System.String                                       passPhrase;
    System.String                                       saltValue;
    System.Int32                                        passwordIterations;
    System.String                                       initVector;
    System.Int32                                        keySize;
    System.Text.Encoding                                asciiEncoding;
    System.Text.Encoding                                utf8Encoding;
    System.Byte[]                                       initVectorBytes;
    System.Byte[]                                       saltValueBytes;
    System.Byte[]                                       plainTextBytes;
    System.Byte[]                                       keyBytes;
    System.Byte[]                                       cipherTextBytes;
    System.Security.Cryptography.Rfc2898DeriveBytes     password;
    System.Security.Cryptography.RijndaelManaged        symmetricKey;
    System.Security.Cryptography.ICryptoTransform       encryptor;
    System.Security.Cryptography.ICryptoTransform       decryptor;
    System.IO.MemoryStream                              memoryStream;
    System.Security.Cryptography.CryptoStream           cryptoStream;
    System.String                                       plainText, cipherText;
    System.Exception                                    e;
}
//New Method
public str decrypt(str _cipherText)
{
    System.String plainValue;

    this.init();

    plainValue = this.decrypt_san(
        _cipherText,
        passPhrase,
        saltValue,
        passwordIterations,
        initVector,
        keySize);

    return plainValue;
}
//New Method
protected System.String decrypt_san(
    str             _cipherText,
    System.String   _passPhrase,
    System.String   _saltValue,
    System.Int32    _passwordIterations,
    System.String   _initVector,
    System.Int32    _keySize)
{
    System.Int32 plainTextBytesLength, cipherTextBytesLength, decryptedByteCount;

    try
    {
        new InteropPermission(InteropKind::ClrInterop).assert();

        asciiEncoding           = System.Text.Encoding::get_ASCII();
        utf8Encoding            = System.Text.Encoding::get_UTF8();
        initVectorBytes         = asciiEncoding.GetBytes(_initVector);
        saltValueBytes          = asciiEncoding.GetBytes(_saltValue);
        cipherTextBytes         = System.Convert::FromBase64String(_cipherText);

        password = new System.Security.Cryptography.Rfc2898DeriveBytes(
            _passPhrase,
            saltValueBytes,
            _passwordIterations);

        keyBytes                = password.GetBytes(_keySize);
        symmetricKey = new System.Security.Cryptography.RijndaelManaged();//RijndaelManaged
        symmetricKey.set_Mode(System.Security.Cryptography.CipherMode::CBC);
        decryptor               = symmetricKey.CreateDecryptor(
            keyBytes,
            initVectorBytes);

        memoryStream = new System.IO.MemoryStream(cipherTextBytes);
        cryptoStream = new System.Security.Cryptography.CryptoStream(
            memoryStream,
            decryptor,
            System.Security.Cryptography.CryptoStreamMode::Read);

        cipherTextBytesLength   = cipherTextBytes.get_Length();
        plainTextBytes          = System.Convert::FromBase64String(_cipherText);
        plainTextBytesLength    = plainTextBytes.get_Length();
        decryptedByteCount      = cryptoStream.Read(plainTextBytes, 0, plainTextBytesLength);
        plainText = utf8Encoding.GetString(plainTextBytes, 0, decryptedByteCount);
        memoryStream.Close();
        cryptoStream.Close();

    }
    catch (Exception::CLRError)
    {
        e = CLRInterop::getLastException();

        while( e )
        {
            info( e.get_Message() );
            e = e.get_InnerException();
        }
    }

    return plainText;
}
//New Method
public str encrypt(str _plainText)
{
    System.String cipherValue;

    this.init();

    cipherValue = this.encrypt_San(
        _plainText,
        passPhrase,
        saltValue,
        passwordIterations,
        initVector,
        keySize);

    return cipherValue;
}
//New Method
protected System.String encrypt_San(
    str             _plainText,
    System.String   _passPhrase,
    System.String   _saltValue,
    System.Int32    _passwordIterations,
    System.String   _initVector,
    System.Int32    _keySize)
{
    try
    {
        new InteropPermission(InteropKind::ClrInterop).assert();

        asciiEncoding       = System.Text.Encoding::get_ASCII();
        utf8Encoding        = System.Text.Encoding::get_UTF8();
        initVectorBytes     = asciiEncoding.GetBytes(_initVector);
        saltValueBytes      = asciiEncoding.GetBytes(_saltValue);
        plainTextBytes      = utf8Encoding.GetBytes(_plainText);
        password            = new System.Security.Cryptography.Rfc2898DeriveBytes(
            _passPhrase,
            saltValueBytes,
            _passwordIterations);

        keyBytes            = password.GetBytes(_keySize);
        symmetricKey        = new System.Security.Cryptography.RijndaelManaged();
        symmetricKey.set_Mode(System.Security.Cryptography.CipherMode::CBC);
        encryptor           = symmetricKey.CreateEncryptor(
            keyBytes,
            initVectorBytes);

        memoryStream        = new System.IO.MemoryStream();
        cryptoStream        = new System.Security.Cryptography.CryptoStream(memoryStream,
            encryptor,
            System.Security.Cryptography.CryptoStreamMode::Write);

        cryptoStream.Write(plainTextBytes, 0, plainTextBytes.get_Length());
        cryptoStream.FlushFinalBlock();

        cipherTextBytes     = memoryStream.ToArray();
        cipherText          = System.Convert::ToBase64String(cipherTextBytes);

        memoryStream.Close();
        cryptoStream.Close();

    }
    catch (Exception::CLRError)
    {
        e = CLRInterop::getLastException();

        while( e )
        {
            info( e.get_Message() );
            e = e.get_InnerException();
        }
    }

    return cipherText;
}
//New Method
protected void init()
{
    passPhrase          = #fixedPassPhrase;         // can be any string
    saltValue           = #fixedSaltValue;          // can be any string
    passwordIterations  = #fixedPasswordIterations; // can be any number
    initVector          = #fixedInitVector;         // must be 16 bytes
    keySize             = #fixedKeySize;            // 32 = 256b, 24=192b or 16=128b
}
// Encrypt and Decrypt Done....


//Encrypt and Decrypt in SQL

https://sangeethwiki.blogspot.in/2017/10/encrypt-and-decrypt-in-sql.html

Count of day without Friday,saturday in ax 2012

// Count of day without Friday,saturday

static void San_DateFriSat(Args _args)
{
    date d,f,g;
    int i,months,day,countday;
    d = mkDate(01,12,2014);
    f = mkDate(31,12,2014);
    g = nextMth(f);  
    months = intvNo(g,d,intvScale::Day);
    //info(strfmt("%1",months));
    for (i=0;i<= months;i++)
    {
        day = dayOfwk(d);
        //info(strfmt("Weekday number - %1",day));
        if (day == 1 || day == 2 || day == 3 || day == 4 || day ==7)
        {
             countday++;  
        }
        d = d +1;
    }
    info(strFmt("%1",countday));
   
}

Random password both Number and String in ax 2012

// Random password

static void RandomNumberString(Args _args)
{
    //RandomGenerate RandomRange = new RandomGenerate();
    //Random Random = new Random();
    //;
    //info(int2Str(RandomRange.randomInt(20,100)));
    //info(int2Str(Random.nextInt()));

    int i;
    RandomGenerate random = new RandomGenerate();
    str password;
    int passwordLength = 8
    ;
    for (i=1; i<= max(2, passwordLength); i++)
    {
        if (i mod 2)
            password += num2char(random.randomInt(char2num('a', 1), char2num('z', 1)));
        else
            password += num2char(random.randomInt(char2num('0', 1), char2num('9', 1)));
    }
    info(password);
}

Sunday, November 16, 2014

Date interval Month

// Date Between the interval Month

static void dateintervalmonth(Args _args)
{
    date d,f;
    int i,months;
    int interval = 8;
    d = mkDate(01,02,2014);
    f = mkDate(01,11,2013);
 
    months = intvNo(d,f,intvScale::YearMonth);
    info(strFmt("%1",months));
 
    for(i = 0;i<= months; i++)
    {
        info(strFmt("%1 - %2",mthname(mthofYr(d)),year(d)));
        d = prevmth(d);
    }
}

Friday, November 14, 2014

Report Parameter to run X++

// Report Parameter to run X++

static void ReportParameterRUn(Args _args)
{
    MenuFunction    BurkanReport; //CopyOfCommercialEvaluation
    Args    args;
    str parmId;
   
    BurkanReport = new MenuFunction(menuitemOutputStr(CopyOfCommercialEvaluation),MenuItemType::Output);
    args = new Args();
    parmId = "00000088_183";
    args.parm(parmId);
    BurkanReport.run(args);
}

Enum Element Label X++

//Enum Element Label X++

static void enumElementLabel(Args _args)
{
    SysDictEnum dictEnum = new SysDictEnum(enumNum(MonthsOfYear));
    Counter values = dictEnum.values();
    int idx;
   
    for(idx = 1; idx< values ;idx++)
    {
        info(strfmt("%1",dictEnum.index2Label(idx)));
    }
}

Sunday, October 26, 2014

Alert New in AX 2012

// Alert  New in AX

class SendEventAlert
{
}
static void sendAlerts_ItemMaster(str   _bodyMsg,str _subject,ItemId _item/*, UBMModelDeatils   _ubmModelDetails*/)
{
    // commented by Sangeeth
    EventNotificationSync   alert;
    MenuFunction            MenuFunction;
    str                     dataSourceName;
    HcmWorkerRecId          _hcmWorkerId;
    UserId                  _user;
    ;


   // _hcmWorkerId         = SalesQuotationTable::find(_ubmModelDetails.QuotationId).WorkerSalesTaker;
    _user                = DirPersonUser::findWorker(_hcmWorkerId).User;

    dataSourceName  =   tablestr(InventTable);
    MenuFunction    =   new MenuFunction(menuitemdisplaystr(EcoResProductPerCompanyListPage), MenuItemType::Display);
    alert           =   EventNotificationsync::newInfo(_subject,
                                                _bodyMsg,
                                                _bodyMsg,
                                                NoYes::Yes,
                                                curext(),
                                                InventTable::find(_item),
                                                dataSourceName,
                                                MenuFunction);



    alert.parmUserId(_user);

    alert.create();
}
static void sendAlerts_ModelDetails(str   _bodyMsg,str _subject/*, UBMModelReqNo _modelReqNo*/)
{
    // commented by Sangeeth
    EventNotificationSync   alert;
    MenuFunction            MenuFunction;

    str                     dataSourceName;
    SecurityRole    _securityRole;
    SecurityUserRole    _securityUserRole;
    ;

    //dataSourceName  =   tablestr(UBMModelDeatils);
   //// MenuFunction    =   new MenuFunction(menuitemdisplaystr(UBMModelDeatils), MenuItemType::Display);
    //alert           =   EventNotificationsync::newInfo(_subject,
                                                //_bodyMsg,
                                                //_bodyMsg,
                                                //NoYes::Yes,
                                                //curext(),
                                                //UBMModelDeatils::find(_modelReqNo),
                                                //dataSourceName,
                                                //MenuFunction);



    select _securityRole
        where _securityRole.Name == 'Estimator';

    while select _securityUserRole
            where _securityUserRole.SecurityRole == _securityRole.RecId
    {
        alert.parmUserId(_securityUserRole.User);
        alert.create();
    }
}
static void sendAlerts_SalesQuote(str   _bodyMsg,str _subject, PurchRFQCaseId _rFQCaseId)
{

    EventNotificationSync   alert;
    MenuFunction            MenuFunction;

    str                     dataSourceName;
    SecurityRole    _securityRole;
    SecurityUserRole    _securityUserRole;
    ;

    dataSourceName  =   tablestr(PurchRFQCaseTable);
    MenuFunction    =   new MenuFunction(menuitemdisplaystr(PurchRFQCaseTable), MenuItemType::Display);
    alert           =   EventNotificationsync::newInfo(_subject,
                                                _bodyMsg,
                                                _bodyMsg,
                                                NoYes::Yes,
                                                curext(),
                                                PurchRFQCaseTable::find(_rFQCaseId),
                                                dataSourceName,
                                                MenuFunction);



    select _securityRole
        where _securityRole.Name == 'Estimator';

    while select _securityUserRole
            where _securityUserRole.SecurityRole == _securityRole.RecId
    {
        alert.parmUserId(_securityUserRole.User);
        alert.create();
    }
}
static void sendAlerts_SendbyDivisionManagers(str   _bodyMsg,str _subject/*,UBMTmpSalesForecastEntryForm   _TmpSalesForecastEntryForm*/)
{
    // commented by Sangeeth
    EventNotificationSync       alert;
    MenuFunction                MenuFunction;
    str                         dataSourceName;
    UserId                      _user;
    HcmPositionRecId            _salesExecutivePosition,_salesManagerPosition;
    HcmWorkerRecId              _SalesManager;
    //UBMSalesForecastEntryForm       _salesForecastEntryForm;

    ;
    //select firstonly _salesForecastEntryForm
        //where _salesForecastEntryForm.RecId == _TmpSalesForecastEntryForm.Parantrecid;
    //_user = DirPersonUser::findWorker(_salesForecastEntryForm.EmployeeId).User;
//
    //dataSourceName  =   tablestr(UBMSalesForecastEntryForm);
    //MenuFunction    =   new MenuFunction(menuitemdisplaystr(UBMSalesForecastEntryForm), MenuItemType::Display);
    //alert           =   EventNotificationsync::newInfo(_subject,
                                                //_bodyMsg,
                                                //_bodyMsg,
                                                //NoYes::Yes,
                                                //curext(),
                                                //_salesForecastEntryForm,
                                                //dataSourceName,
                                                //MenuFunction);



    alert.parmUserId(_user);

    alert.create();
}
static void sendAlerts_SendbyRegManagers(str   _bodyMsg,str _subject/*,UBMTmpSalesForecastEntryForm   _salesForecastEntryForm*/)
{
    // commented by Sangeeth
    EventNotificationSync       alert;
    MenuFunction                MenuFunction;
    str                         dataSourceName;
    UserId                      _user;
    HcmPositionRecId            _salesExecutivePosition,_salesManagerPosition;
    HcmWorkerRecId              _SalesManager;
    HcmPositionWorkerAssignment _hcmPositionWorkerAssignment;
    ;
    select _hcmPositionWorkerAssignment
        where _hcmPositionWorkerAssignment.Worker == Global::currentWorker();
    _salesExecutivePosition = HcmPositionHierarchy::findByPosition(_hcmPositionWorkerAssignment.Position).ParentPosition;
    _SalesManager = HcmPositionWorkerAssignment::findByPosition(_salesExecutivePosition).Worker;
    _user = DirPersonUser::findWorker(_SalesManager).User;

    //dataSourceName  =   tablestr(UBMSalesForecastEntryForm);
    //MenuFunction    =   new MenuFunction(menuitemdisplaystr(UBMTMPSalesForecastEntryForm), MenuItemType::Display);
    //alert           =   EventNotificationsync::newInfo(_subject,
                                                //_bodyMsg,
                                                //_bodyMsg,
                                                //NoYes::Yes,
                                                //curext(),
                                                //_salesForecastEntryForm,
                                                //dataSourceName,
                                                //MenuFunction);



    alert.parmUserId(_user);

    alert.create();
}
static void sendAlerts_SendbySalesExecutive(str   _bodyMsg,str _subject/*,UBMSalesForecastEntryForm   _salesForecastEntryForm*/)
{
    // commented by Sangeeth
    EventNotificationSync       alert;
    MenuFunction                MenuFunction;
    str                         dataSourceName;
    UserId                      _user;
    HcmPositionRecId            _salesExecutivePosition,_salesManagerPosition;
    HcmWorkerRecId              _SalesManager;
    //UBMTmpSalesForecastEntryForm    _ubmTmpSalesForecastEntryForm;

    ;
   // _salesExecutivePosition = HcmPositionHierarchy::find(_salesForecastEntryForm.Positionrecid).ParentPosition;
    //select _ubmTmpSalesForecastEntryForm
        //where _ubmTmpSalesForecastEntryForm.Parantrecid == _salesForecastEntryForm.RecId;
    //_SalesManager = HcmPositionWorkerAssignment::findByPosition(_salesForecastEntryForm.Positionrecid).Worker;
    //_user = DirPersonUser::findWorker(_SalesManager).User;
//
    //dataSourceName  =   tablestr(UBMSalesForecastEntryForm);
    //MenuFunction    =   new MenuFunction(menuitemdisplaystr(UBMSalesForecastEntryForm), MenuItemType::Display);
    //alert           =   EventNotificationsync::newInfo(_subject,
                                                //_bodyMsg,
                                                //_bodyMsg,
                                                //NoYes::Yes,
                                                //curext(),
                                                //_ubmTmpSalesForecastEntryForm,
                                                //dataSourceName,
                                                //MenuFunction);



    alert.parmUserId(_user);

    alert.create();
}
static void sendAlerts_UpdatedSalesPrice( str   _bodyMsg,str _subject,QuotationId _quotationId )
{
    // commented by Sangeeth
    EventNotificationSync   alert;
    MenuFunction            MenuFunction;
    HcmWorkerRecId          _hcmWorkerId;
    UserId                  _user;
    SalesQuotationTable     _SalesQuotationTable;
   // EnquiryNo               _enquiryNo;
    str                     dataSourceName;
    ;
    //_enquiryNo           = SalesQuotationTable::find(_quotationId).UBMRefEnquiryNo;
    //_hcmWorkerId         = SalesQuotationTable::find(_enquiryNo).WorkerSalesTaker;
    _user                = DirPersonUser::findWorker(_hcmWorkerId).User;
    dataSourceName  =   tablestr(SalesQuotationTable);
    MenuFunction    =   new MenuFunction(menuitemdisplaystr(SalesQuotationTableDetails), MenuItemType::Display);
    alert           =   EventNotificationsync::newInfo(_subject,
                                                _bodyMsg,
                                                _bodyMsg,
                                                NoYes::Yes,
                                                curext(),
                                                SalesQuotationTable::find(_quotationId),
                                                dataSourceName,
                                                MenuFunction);



    alert.parmUserId(_user);

    alert.create();
}

Hirerachy position and QueryToRDP Report Example


// based on the Hirerachy position value ill display
static void hirerachypositionandReportQuerytoRdp(Args _args)
{
     str UserId;

    // Hierarchy position test class
    // HierarchyPosition Table
    /*class RecursionPosition
    {
        str UserId;
    }
    void recursiveCallProj(HcmPositionRecid    _position = 0)
    {
    HcmPositionHierarchy HcmPositionHierarchy;
    HierarchyPosition   hierarchyPosition;
    HcmPosition         posi;
    HcmWorker           work;
    int64               recid;
    ;
    while select HcmPositionHierarchy
    where HcmPositionHierarchy.ParentPosition == _position
    {
        // setprefix("1");
        //info(strFmt("%1",HcmPositionHierarchy.Position));
        select Posi where posi.RecId == HcmPositionHierarchy.Position;
        recid = hcmposition::getWorker(posi.RecId);
        select work where work.RecId == recid;
        hierarchyPosition.Position = work.RecId;
        hierarchyPosition.userid = curuserid();
        hierarchyPosition.insert();

        this.recursiveCallProj(HcmPositionHierarchy.Position);

        }
        }
    public static void postion(str userid = curUserId())
    {
    HcmPositionRecid        _position; //= 5637144597;
    HcmPositionHierarchy    HcmPositionHierarchy;
    RecursionPosition       RecursionPosition;
    HcmPosition             posi;
    int64                   recid;
    HcmWorker               work;
    HierarchyPosition   hierarchyPosition;
    //str UserId;

    ;
    //UserId = user;
    _position = HcmPositionWorkerAssignment::getActivePositionWorkerAssignment(HcmWorker::find(HcmWorker::userId2Worker(userid)).RecId).Position;
    //_position = HcmPositionWorkerAssignment::getActivePositionWorkerAssignment(HcmWorker::findByPersonnelNumber(personnelno).RecId).Position;
    RecursionPosition = new RecursionPosition();


    while select HcmPositionHierarchy
    where HcmPositionHierarchy.Position == _position
    {
        info(strFmt("%1",HcmPositionHierarchy.Position));
        select Posi where posi.RecId == HcmPositionHierarchy.Position;
        recid = hcmposition::getWorker(posi.RecId);
        select work where work.RecId == recid;
        hierarchyPosition.Position = work.RecId;
        hierarchyPosition.userid = curUserId();
        hierarchyPosition.insert();


        RecursionPosition.recursiveCallProj(HcmPositionHierarchy.Position);

    }


    }
    // Example QUery report to RDP Report class Example
    [
    SRSReportQueryAttribute(queryStr(UBMSalesEnquiryTable))
    ]





// Query TO rdp

    class UBMSalesEnquiryRegisterDP extends SRSReportDataProviderBase
    {

        UBMSalesEnquiryRegisterTmp     SalesEnquiryRegisterTmp;

    }
    private Query buildQuery(
    Query           _query,
    str             _worker)
    {

        // Add the date range on all three data sources to allow SQL to restrict the records as much as possible prior to processing
        _query.dataSourceTable(tableNum(SalesQuotationTable), 1).addRange(fieldNum(SalesQuotationTable, WorkerSalesResponsible)).value(_worker);

        return _query;
    }
    [SRSReportDataSetAttribute("UBMSalesEnquiryRegisterTmp")]
    public UBMSalesEnquiryRegisterTmp getUBMSalesEnquiryRegisterTmp()
    {
        select * from SalesEnquiryRegisterTmp;
        return  SalesEnquiryRegisterTmp;
    }
    [SysEntryPointAttribute(false)]
    public void processReport()
    {
    QueryRun                queryRun;
    SalesQuotationTable     salesQuotationTable;
    HcmWorker               hcmWorker;
    str                     workerHirerchy;
    //helper.amountRemainSalesPhysical(this.SalesTableRecId);

    HierarchyPosition    hierarchyPosition;
    boolean     first = true;


    delete_from hierarchyPosition;

    RecursionPosition::postion();


    while select hierarchyPosition //where currency.CurrencyCode like "E*"
    {
        if(first)
        {
            workerHirerchy = strFmt("%1,",hierarchyPosition.Position);
            first = false;
        }
        else
        {

            workerHirerchy += strFmt("%1,",hierarchyPosition.Position);
        }

    }

    queryRun = new QueryRun(this.buildQuery(this.parmQuery(),workerHirerchy));

    //queryRun = new QueryRun(this.parmQuery());

    while (queryRun.next())
    {
        salesQuotationTable                                 = queryRun.get(tableNum(SalesQuotationTable));

        SalesEnquiryRegisterTmp.QuotationId                        = salesQuotationTable.QuotationId;
        SalesEnquiryRegisterTmp.QuotationName                      = salesQuotationTable.QuotationName;
        SalesEnquiryRegisterTmp.CreateDate                         = salesQuotationTable.createDate();
        SalesEnquiryRegisterTmp.CustomerRef                        = salesQuotationTable.CustomerRef;
        SalesEnquiryRegisterTmp.CustName                           = salesQuotationTable.customerName();
        SalesEnquiryRegisterTmp.LineAmount                         = salesQuotationTable.lineAmount();
        SalesEnquiryRegisterTmp.UBMrefenquiryno                    = salesQuotationTable.UBMrefenquiryno;
        SalesEnquiryRegisterTmp.VendName                           = salesQuotationTable.VendName();
        SalesEnquiryRegisterTmp.MOE                                = salesQuotationTable.SalesOriginId;
        SalesEnquiryRegisterTmp.QuotationStatus                    = salesQuotationTable.QuotationStatus;
        SalesEnquiryRegisterTmp.ReasonId                           = salesQuotationTable.ReasonId;
        SalesEnquiryRegisterTmp.UBMEnquiryDate                     = salesQuotationTable.UBMEnquiryDate;
        SalesEnquiryRegisterTmp.WorkerSalesResponsible             = HcmWorker::find(salesQuotationTable.WorkerSalesResponsible).name();
        SalesEnquiryRegisterTmp.QuotationCategory                  = salesQuotationTable.QuotationCategory;
        SalesEnquiryRegisterTmp.Competitor                         = " ";
        SalesEnquiryRegisterTmp.insert();


    }


}*/
}

Item Price Analysis Code %%%

// Item Price Analysis Code %%%

 InventTable         inventTable;
    InventTrans         inventTrans;
    InventSum               inventSum;
    Query                   query;
    QueryBuildDataSource    qbds;
    QueryBuildRange         qbrItemid,qbrItemGroup;
    QueryRun                qr;
    DimensionAttributeValueSetStorage   dimStorage;
    InventTableModule       inventTableModule;
    CustInvoiceTrans        custInvoiceTransMax,custInvoiceTrans,custInvoiceTransMin;
    InventTransOrigin       inventTransOrigin;
    Amount                  amount,minPrice,amountDiv,sales25,sales50,sales75,sales100;
    int i;

    super();
    delete_from itempriceAnalysis;
    query = new Query();
    qbds = query.addDataSource(tableNum(InventTable));
    _item = ItemId.valueStr();
    _itemBuyerGroup = ItemGroup.valueStr();
    _subDivision = SubDivision.valueStr();
    if(_item)
    {
        qbrItemid = qbds.addRange(fieldNum(InventTable,ItemId));
        qbrItemid.value(strReplace(_item,";",","));
    }
    if(_itemBuyerGroup)
    {
        qbrItemGroup = qbds.addRange(fieldNum(InventTable,ItemBuyerGroupId));
        qbrItemGroup.value(strReplace(_itemBuyerGroup,";",","));
    }
    qr = new QueryRun(query);
    while(qr.next())
    {
        inventTable = qr.get(tableNum(InventTable));

        dimStorage = DimensionAttributeValueSetStorage::find(inventTable.DefaultDimension);
        itempriceAnalysis.clear();
        if (_subDivision && (_subDivision!= dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName('SubDivisions').RecId)))
        {
                continue;
        }
        itempriceAnalysis.SubDivision = dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName('SubDivisions').RecId);
        itempriceAnalysis.ItemId = inventTable.ItemId;
        itempriceAnalysis.ItemBuyerGroupId = inventTable.ItemBuyerGroupId;
        itempriceAnalysis.ItemName = inventTable.itemName();
        select inventSum where inventSum.ItemId == inventTable.ItemId;
        itempriceAnalysis.CurrentUnitCost = inventSum.averageCostPrice();

        select * from inventTrans order by RecId desc
                where inventTrans.ItemId == inventTable.ItemId
                        && inventTrans.StatusReceipt == StatusReceipt::Purchased
                join inventTransOrigin where inventTransOrigin.RecId == inventTrans.InventTransOrigin
                                && inventTransOrigin.ReferenceCategory == InventTransType::Purch;
             itempriceAnalysis.LastPurchasePrice =  inventTrans.costValue();

        select minof(SalesPrice) from custInvoiceTransMin
                where custInvoiceTransMin.ItemId == inventTable.ItemId;
            itempriceAnalysis.LowestSalesPrice = custInvoiceTransMin.SalesPrice;

        select maxOf(SalesPrice) from custInvoiceTransMax
                where custInvoiceTransMax.ItemId == inventTable.ItemId;
            itempriceAnalysis.HighestSalesPrice = custInvoiceTransMax.SalesPrice;
           amount = custInvoiceTransMax.SalesPrice - custInvoiceTransMin.SalesPrice;

        amountDiv   = amount/4;
        //if (amountDiv != 0.00)
        //{
            minPrice    = custInvoiceTransMin.SalesPrice;
            sales25     = minPrice + amountDiv;
            sales50     = sales25 + amountDiv;
            sales75     = sales50 + amountDiv;
            sales100    = sales75 + amountDiv;


        while select custInvoiceTrans
                where custInvoiceTrans.ItemID == inventTable.ItemId
        {

            if(custInvoiceTrans.SalesPrice >= minPrice && custInvoiceTrans.SalesPrice <= sales25)
                itempriceAnalysis.SalesValue25 += custInvoiceTrans.LineAmount;
            if(custInvoiceTrans.SalesPrice > sales25 && custInvoiceTrans.SalesPrice <= sales50)
                itempriceAnalysis.SalesValue50 += custInvoiceTrans.LineAmount;
             if(custInvoiceTrans.SalesPrice > sales50 && custInvoiceTrans.SalesPrice <= sales75)
                itempriceAnalysis.SalesValue75 += custInvoiceTrans.LineAmount;
             if(custInvoiceTrans.SalesPrice > sales75 && custInvoiceTrans.SalesPrice <= sales100)
                itempriceAnalysis.SalesValue100 += custInvoiceTrans.LineAmount;

        }

        //}

        itempriceAnalysis.insert();

    }
    ItemPriceAnalysisTmp_ds.research();
    ItemPriceAnalysisTmp_ds.refresh();

Get Default Dimension Value through X++ by default dimension field



// Get Default Dimension Value through X++ by deafault dimension field

dimStorage = DimensionAttributeValueSetStorage::find(salesline.DefaultDimension);

            str  = dimStorage.getDisplayValueByDimensionAttribute(dimensionAttribute::findByName('Divisions').RecId);
           str  = dimStorage.getDisplayValueByDimensionAttribute(dimensionAttribute::findByName('SubDivisions').RecId);
           str  = dimStorage.getDisplayValueByDimensionAttribute(dimensionAttribute::findByName('Provinces').RecId);

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...