Saturday, June 25, 2022

Date and Time functions in D365FO

Date and Time functions in D365FO .


  //The minimum value for the date in x++ is 1/1/1900 and max value is 12/31/2154

    Global::DateNull();
    DateTimeUtil::minValue();//Retrieves the minimum value 
    DateTimeUtil::maxValue();//Retrieves the maximum value 
    utcDateTimeNull();
    dateNull();
    dateMax();

    DateTimeUtil::addDays(utcdatetime, Int); //Add days
    DateTimeUtil::addHours(utcdatetime, Int) // Add hours
    DateTimeUtil::addMinutes(utcdatetime, Int)// Add minutes 
    DateTimeUtil::addMonths(utcdatetime, Int)// Add months  
    DateTimeUtil::addSeconds(utcdatetime, Int)// Add seconds
    DateTimeUtil::addYears(utcdatetime, Int)// Add years

    DateTimeUtil::applyTimeZoneOffset(utcdatetime, Timezone)//  apply Timezone 
    DateTimeUtil::applyTimeZoneOffsetRange(QueryBuildRange)//  Applies the time zone offset to the range.


    DateTimeUtil::year(utcdatetime) // Retrieves the year 
    DateTimeUtil::month(utcdatetime)// Retrieves the month 
    DateTimeUtil::date(utcdatetime)//  Retrieves date 
DateTimeUtil::day(utcdatetime)// Retrieves the day DateTimeUtil::time(utcdatetime)// Retrieves the time DateTimeUtil::minute(utcdatetime)// Retrieves the minute DateTimeUtil::second(utcdatetime) //Retrieves the seconds DateTimeUtil::getClientMachineTimeZone()// Gets the Timezone of client computer. DateTimeUtil::getCompanyTimeZone()// Gets the Timezone valu of current legal entity. DateTimeUtil::getDifference(utcdatetime, utcdatetime) //Gets the number of seconds between                                                         //two specified utcdatetime values. DateTimeUtil::utcNow() //Retrieves the current system time. DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()) //Gets the current system DateTimeUtil::getTimeNow(DateTimeUtil::getUserPreferredTimeZone()) //Gets the current system time DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone()) //Gets the current system date DateTimeUtil::setCompanyTimeZone(Timezone) // Sets the Timezone the current company. DateTimeUtil::setUserPreferredTimeZone(Timezone) //Sets the preferred time zone DateTimeUtil::getUserPreferredTimeZone() //Gets the current system date time DateTimeUtil::removeTimeZoneOffset(utcdatetime, Timezone) //Removes the offset Timezone DateTimeUtil::newDateTime(Date, Int32) //Creates a new utcdatetime . DateTimeUtil::toStr(utcdatetime) // Converts a utcdatetime value to a                                 //string in the following format: YYYY-MM-DDThh:mm:ss,     intVNo(_startDate, _enddate, intvScale::Month) // will get month difference     intVNo(_startDate, _enddate, intvScale::Year) // will get Year difference
    
Keep daxing!!

Upload JSON file from local system using x++

 Upload JSON file from local system using x++ In D365FO.

    FileUploadTemporaryStorageResult    fileUpload  = File::GetFileFromUser() as FileUploadTemporaryStorageResult;
    System.IO.Stream                    stream      = fileUpload.openResult();
    str                                 responceJson;

    using (var reader = new System.IO.StreamReader(stream))
    {
        responceJson = reader.ReadToEnd();
    } 


Keep daxing!!

Get HSN Code using x++

Get the HSN Code for sales line using x++ in D365FO.


  
    TaxDocumentRowTransaction       taxDocumentRowTransaction;
    TaxDocumentRowTransaction_IN    taxDocumentRowTransaction_IN;
    SalesTable                      salesTable;
    SalesLine_IN                    salesLine_IN;
    SalesLine                       salesLine;
    CustInvoiceTrans                _custInvoiceTrans;

    select SalesLine where salesLine.salesId == 'SO-000125';

    _custInvoiceTrans   = CustInvoiceTrans::findInventTransid(salesLine.InventTransId);
    salesLine_IN        = _custInvoiceTrans.salesLine().salesLine_IN();

    Select RecId, TransactionJourLineRecId from taxDocumentRowTransaction
        where taxDocumentRowTransaction.TransactionJourLineRecId == _custInvoiceTrans.RecId
    join HSNCode, TaxDocumentRowTransactionRecId from taxDocumentRowTransaction_IN
        where taxDocumentRowTransaction_IN.TaxDocumentRowTransactionRecId == taxDocumentRowTransaction.RecId;

    if(taxDocumentRowTransaction_IN)
    {
        Info(strFmt('HSN- %1', taxDocumentRowTransaction_IN.HSNCode));

        /*select * from taxTrans where taxTrans.SourceRecId == custInvoiceTrans.RecId
            join taxTrans_IN where taxTrans_IN.RefRecId == taxTrans.RecId;
        if(taxTrans_IN)
        {
            // HSNCodeTable_IN::find(taxTrans_IN.HSNCodeTable).Code;
        }*/
    }
    else
    {
        Info(strFmt('HSN - %1', HSNCodeTable_IN::find(salesLine_IN.HSNCodeTable).Code));
    }

Keep Daxing!!