Pages

Banner 468 x 60px

 

Monday, March 27, 2017

ValidateDelete - Write - ModifiedField - Validate in x++

0 comments
ValidateDelete - Write - ModifiedField - Validate in x++ :

Table methods using ValidateWrite() ValidateDelete() initValue() ModifiedField() - Microsoft Dynamics AX

Table methods using ValidateWrite() ValidateDelete() initValue() ModifiedField()

initValue()This method file while creating new record to initialize a value, here I am assigning user id to the userID field.

public void initValue()
 {
 super();
 this.UserId = curuserid();
 }

ValidateDelete()While deleting a record if we want to put any validation we can use this method. Here once I delete a record populating a info that deleted record.

public boolean validateDelete()
 {
 boolean ret;
 ret = super();
 info(this.AccountNum);
 return ret;
 }

public boolean validateDelete()
{
    boolean ret;

    ret = super();

    if (this.TECClaimInStatus  == TECClaimInStatus::Posted ||
        this.TECClaimInStatus  == TECClaimInStatus::Received ||
        this.TECClaimOutStatus == TECClaimOutStatus::Posted ||
        this.TECClaimOutStatus == TECClaimOutStatus::Delivered)
    {
        ret = false;
        warning('Cannot delete lines!');
    }
    else
    {
        ret = true;
    }

    return ret;
}

ValidateWrite()

This method will get to fire when we update a record. here I am using to check mandatory field for address AccountNum

public boolean validateWrite()
 {
 boolean ret;
 ;
 if(this.Address != "")
 ret = super();
 else
 warning(" Please fill the address value");
 return ret;
 }

public boolean validateWrite()
{
    boolean ret;

    ret = super();

    if (!purchEditLinesForm.validateInventDimId(purchParmLine, inventDim))
    {
        ret = false;
    }

    // add by tyo
    //if (!purchparmLine.TIDRemark)
    if(!TIDCorrectPackingSlip_Remark.mandatory())
    {  
    ret = false;
    error("Remark harus diisi");
    }
    // end by tyo

    return ret;
}

public boolean validateWrite()
{
    boolean                 ret;
    boolean                 check = true;
    boolean                 IsExtraChargeModified;
    boolean                 isAllowDelete;
    SalesLine               SalesLineOriginal = SalesLine.orig();
    ;
       if ( salesline.SalesQty >= 0
         && !SalesTable.isSalesLineAllowNew()
         && showMsgWriteRestriction
         && isAdditionalRow
       )
    {

      showMsgWriteRestriction = CustConfirmJour::exist(SalesTable.SalesId) ? true : false;
      box::stop("For SO Item Contract, after confirmation you not allow to add qty positive again");
      showMsgWriteRestriction = false;
      isAllowDelete  = salesLine_DS.allowDelete();
      salesLine_DS.allowDelete(true);
      salesLine_DS.delete();
      salesLine_DS.allowDelete(isAllowDelete);
      isAdditionalRow = false;
      return false;
    }
    //


    if(!salestable.CheckCustConfirm())
        check = true;
    else
    {

        if (SalesLine == SalesLineOriginal )
        {
           check = true;
        }
        else
        {

           if (salestable.Soltius_ContractType    != Soltius_contractType::ItemContract &&
               salesline.Soltius_AppMoneyContract != Soltius_AppMoneyContract::DeleteProcess   )
           {

               isExtraChargeModified = salesLine &&
                                       salesLine.Soltius_ExtraCharge != salesLine.orig().Soltius_ExtraCharge ? true : false;

               if ( isExtraChargeModified )
               {
                 check = true;
               }
               else
               {

                  if ( !salesLine.ItemId )
                     check = false;

                //  if (box::yesNo("Are you sure want to save this line?", dialogbutton::No,"Confirmation", "Validate Confirmation") == dialogbutton::No)
                //  {
                //     salesLine_ds.reread();
                     //check = false;

                     if ( !salesline.Soltius_ExtraCharge )
                        this.DeleteExtraCharge( salesLine.InventRefId );
                //  }

               }

           }

        }
     }

    if(check)
    {

       salesTableForm.setTouched(salesTable);
       salesLine.InventDimId = InventDim::findOrCreate(inventDim).InventDimId;
       if (salesLine.RecId != 0
           &&  salesLine.InterCompanyInventTransId
           &&  salesTable.InterCompanyOrder)
       {
                salesLine.DeliveryDateControlType = SalesDeliveryDateControlType::None;

       }

        ret = super();

        if (!askingModifyInvoiced && ret)
        {
            askingModifyInvoiced = true;
            ret = salesTable.checkUpdate();
            if (!ret)
            {
                salesLine_ds.reread();
                salesTable_ds.reread();
            }
            askingModifyInvoiced = false;
        }

        if (ret)
        {
           ret = salesTableForm.salesLine_validateWrite(salesLine, inventDim);
        }

        if (ret && salesLine.DeliveryDateControlType)
        {
            ret = SalesCalcAvailableDlvDates::validateWritePrompt(salesLine,false,true,true,false);
        }
    }
    else
    {

        ret = false;
    }

    return ret;
}




ModifiedField()

This method will execute if modified a record value, this works based on the field value.
 Here I am using to fill the name field value according to the AccountNum

public void modifiedField(fieldId _fieldId)
 {
 CustTable ct;
 ;
 super(_fieldId);
 switch(_fieldId)
 {
 case fieldNum(Cust_new,AccountNum) :
 {
 this.Name = CustTable::find(this.AccountNum).Name;
 }
 break;
 }
 }

contoh lain di letakkan di form (bukan di table):
public boolean validate()
{
    boolean ret;

    ret = super();

    if (mthOfYr(ToDate.dateValue()) != mthOfYr(FromDate.dateValue()))
    {
        ret = false;
        warning('Bulan To Date harus sama dengan bulan From Date');
    }

    if (date2num(ToDate.dateValue()) < date2num(FromDate.dateValue()))
    {
        ret = false;
        warning('Tanggal To Date tidak boleh lebih kecil dari From Date');
    }

    return ret;
}

    if(PurchParmTable.TransDate < PurchLine.DeliveryDate && PurchLine.TECIsCancel==NoYes::No && documentStatus == documentStatus::PackingSlip)
    {
        throw error("Posting Date TIDAK BOLEH lebih kecil dari Delivery Date, harap menghubungi bagian Purchasing");
        return;
    }

====== ATAU tanpa return; juga bisa =======
 
   if(PurchParmTable.TransDate < PurchLine.DeliveryDate && PurchLine.TECIsCancel==NoYes::No && documentStatus == documentStatus::PackingSlip)
    {
        throw error("Posting Date TIDAK BOLEH lebih kecil dari Delivery Date, harap menghubungi bagian Purchasing");
    }

    else
    {
        brake;
    }


public boolean validate()
{
    boolean ret;

    ret = super();

    if (ret)
    {
        if (this.value() == true && logisticsElectronicAddress.otherPrimaryExists())
        {
            if (Box::yesNo("@SYS304427", DialogButton::No) == DialogButton::No)
            {
                ret = false;
            }
        }
    }

    return ret;
}


// added by adit
public boolean modified()
{
    Inventtrans         inventTransReturn;
    SalesOrderedQty     _SalesQty, a, b, c;
    InventSplitTrans    splitTrans;
    InventQty           qtyRemain;
    boolean             ret;

    ret = super();

    while select inventTransReturn where inventTransReturn.RecId == salesline.Soltius_InventReturnRecId
    {
        info(strfmt('%1 == %2',  inventTransReturn.RecId, salesline.Soltius_InventReturnRecId));

        b = salesline.SalesQty;
        info(strfmt('%1', b));
        select SalesQty from salesline where salesline.Soltius_InventReturnRecId == inventTransReturn.RecId;
        _SalesQty = a + salesline.SalesQty;

        c = b + _salesqty;
        info(strfmt('%1', c));

        info(strfmt('total _SalesQty = %1 dengan recid = %2', c, inventTransReturn.RecId));

        info(strfmt('total _SalesQty = %1 < inventtrans = %2', c, inventTransReturn.qty));
        if(c < inventTransReturn.Qty)
        {
         error("@SYS53004");
         ret = false;
        }
     }

    return ret;
}
//ended by adit


============================

public boolean validate()
{
    boolean ret;

    ret = super();

     if(Advance.value() == noyes::Yes || Cash.value() == noyes::Yes || Credit.value() == noyes::Yes)
    {      
        ret = false;
warning("Pilih salah satu");
    }

    return ret;
}

=========================================================
void OK_Button()
{
    GG_FPJVoucher       _GG_FPJVoucher1, GG_FPJVoucher2 ;
    str                 TempTxt1, TempTxt2;
    Args                _Args;
    ;

    // added by adit
    if(Retention.value() == noyes::No && Cash.value() == noyes::No && Credit.value() == noyes::No && Advance.value() == noyes::No)
    {
        error("Maaf, Anda belum memilih jenis transaksi");
        return;
    }
    // ended by adit

    if (GG_FPJVoucher_TotalVoucherAmount.realValue() != 0)
    {
            If ((PPNPercent.realValue() == 0 && Berikat.value() == NoYes::Yes) ||
                (PPNPercent.realValue() != 0 && Berikat.value() == NoYes::No)  ||
                (PPNPercent.realValue() == 0 && Element.CreateFaktur(GG_FPJVoucher2.Voucher)))
            {
                if (box::yesNo("Are you sure to save ?", dialogButton::No, "Confirmation")  == dialogButton::Yes)
                {
                    select _GG_FPJVoucher1 index hint voucheridx where _GG_FPJVoucher1.Voucher    == GG_FPJVoucher_Voucher.text();


                    // ================================== Untuk input voucher baru ============================================
                    if (!_GG_FPJVoucher1)
                    {
                        if (element.checkDateValidation(GG_FPJVoucher_CustAccount.text(), GGSalesID.text(), GG_FPJVoucher_VoucherDate.dateValue()))
                        {
                            //num seq
                            TempTxt2        = GG_FPJParameter::getnextStrId(1, OverwriteNextNum.value());
                            //
                            Try
                            {
                                ttsbegin;
                                GG_FPJVoucher2.clear();
                                GG_FPJVoucher2.Voucher              = GG_FPJVoucher_Voucher.text();
                                GG_FPJVoucher2.CurrencyCode         = GG_FPJVoucher_CurrencyCode.text();
                                GG_FPJVoucher2.JournalId            = GG_FPJVoucher_JournalId.text();
                                GG_FPJVoucher2.VoucherDate          = GG_FPJVoucher_VoucherDate.dateValue();
                                GG_FPJVoucher2.FPJVoucherId         = TempTxt2;
                                GG_FPJVoucher2.CustAccount          = GG_FPJVoucher_CustAccount.text();
                                GG_FPJVoucher2.TotalVoucherAmount   = GG_FPJVoucher_TotalVoucherAmount.realValue();
                                GG_FPJVoucher2.DPPBaseAmount        = GG_FPJVoucher_DPPBaseAmount.realValue();
                                GG_FPJVoucher2.PPNBaseAmount        = GG_FPJVoucher_PPNBaseAmount.realValue();
                                GG_FPJVoucher2.PPhBaseAmount        = GG_FPJVoucher_PPhBaseAmount.realValue();
                                GG_FPJVoucher2.FPJExchRate          = GG_FPJVoucher_FPJExchRate.realValue();
                                GG_FPJVoucher2.PPhExchRate          = GG_FPJVoucher_PPhExchRate.realValue();
                                GG_FPJVoucher2.FPJVoucherType       = GG_FPJVoucher_FPJVoucherType.selection();
                                GG_FPJVoucher2.SalesId              = GGSalesID.text();
                                GG_FPJVoucher2.VATPercent           = PPNPercent.realValue();
                                GG_FPJVoucher2.PPhPercent           = PPhPercent.realValue();
                                GG_FPJVoucher2.RetensiPercent       = RetensiPercent.realValue();
                                GG_FPJVoucher2.RetensiAmount        = RetensiAmount.realValue();
                                GG_FPJVoucher2.UangMuka             = Advance.value();

                                // added by adit
                                GG_FPJVoucher2.Retensi              = Retention.value();
                                GG_FPJVoucher2.BIT_Cash             = Cash.value();
                                GG_FPJVoucher2.BIT_Credit           = Credit.value();
                                GG_FPJVoucher2.BIT_KodePajak        = BIT_KodePajak.valueStr();
                                // ended by adit

                                GG_FPJVoucher2.AlocFPJNum           = OthFaktur.text();
                                GG_FPJVoucher2.Berikat              = Berikat.value();
                                //Breakpoint;
                                If ((Element.CreateFaktur(GG_FPJVoucher2.Voucher)) && ((GG_FPJVoucher2.VATPercent || GG_FPJVoucher2.PPhPercent) || Berikat.value()==NoYes::Yes))
                                    [GG_FPJVoucher2.AmountDPPFaktur, GG_FPJVoucher2.AmountPPNFaktur, GG_FPJVoucher2.AmountPPhFaktur]    = element.calculateAmountFakturTRY(GG_FPJVoucher2.Voucher, GG_FPJVoucher2.SalesId);
                                Else
                                    [GG_FPJVoucher2.AmountDPPFaktur, GG_FPJVoucher2.AmountPPNFaktur, GG_FPJVoucher2.AmountPPhFaktur]    = [0, 0, 0];

                                //Breakpoint;
                                IF ((GG_FPJVoucher2.AmountPPNFaktur > 0) && (GG_FPJVoucher2.AmountPPhFaktur == 0))
                                    GG_FPJVoucher2.Status       = GG_OpenClose::OpenVAT;

                                ELSE IF ((GG_FPJVoucher2.AmountPPNFaktur == 0) && (GG_FPJVoucher2.AmountPPhFaktur > 0))
                                {
                                    If (Berikat.value() != NoYes::Yes)
                                    GG_FPJVoucher2.Status       = GG_OpenClose::OpenPPh;
                                }
                                ELSE IF ((GG_FPJVoucher2.AmountPPNFaktur > 0) && (GG_FPJVoucher2.AmountPPhFaktur > 0))
                                    GG_FPJVoucher2.Status       = GG_OpenClose::Open;

                                ELSE IF ((GG_FPJVoucher2.AmountPPNFaktur == 0) && (GG_FPJVoucher2.AmountPPhFaktur == 0))
                                {
                                    GG_FPJVoucher2.Status       = GG_OpenClose::Closed;
                                }

                                If ((Berikat.value() == NoYes::Yes) && (GG_FPJVoucher2.AmountDPPFaktur != 0))
                                    GG_FPJVoucher2.Status       = GG_OpenClose::Open;

                                IF (SalesTable::find(GG_FPJVoucher2.SalesId).GGRetensi)
                                    GG_FPJVoucher2.calculateAmountFakturRetensi();

                                GG_FPJVoucher2.insert();
                                ttscommit;
                                info(strfmt("Data Inserted (Id : %1)", GG_FPJVoucher2.FPJVoucherId));
                                element.close();
                            }
                            catch
                            {
                                error("Process error");
                                ttsabort;
                            }

                        }
                        else
                            warning("Older Voucher date already exist in the same Customer account, please check transaction");
                    }
                    else
                    {
                            warning("Voucher Already Exist, Cannot Proceed !");
                    }







 //======== Untuk voucher yang sudah pernah di input dan ingin dibatalkan =========
                    if (_GG_FPJVoucher1 && GG_FpjVoucher::FindVoucher(GG_FPJVoucher_Voucher.valueStr()).BIT_Batal == noyes::Yes)
                    {
                        if (element.checkDateValidation(GG_FPJVoucher_CustAccount.text(), GGSalesID.text(), GG_FPJVoucher_VoucherDate.dateValue()))
                        {
                            //num seq
                            TempTxt2        = GG_FPJParameter::getnextStrId(1, OverwriteNextNum.value());
                            //
                            Try
                            {
                                ttsbegin;
                                GG_FPJVoucher2.clear();
                                GG_FPJVoucher2.Voucher              = GG_FPJVoucher_Voucher.text();
                                GG_FPJVoucher2.CurrencyCode         = GG_FPJVoucher_CurrencyCode.text();
                                GG_FPJVoucher2.JournalId            = GG_FPJVoucher_JournalId.text();
                                GG_FPJVoucher2.VoucherDate          = GG_FPJVoucher_VoucherDate.dateValue();
                                GG_FPJVoucher2.FPJVoucherId         = TempTxt2;
                                GG_FPJVoucher2.CustAccount          = GG_FPJVoucher_CustAccount.text();
                                GG_FPJVoucher2.TotalVoucherAmount   = GG_FPJVoucher_TotalVoucherAmount.realValue();
                                GG_FPJVoucher2.DPPBaseAmount        = GG_FPJVoucher_DPPBaseAmount.realValue();
                                GG_FPJVoucher2.PPNBaseAmount        = GG_FPJVoucher_PPNBaseAmount.realValue();
                                GG_FPJVoucher2.PPhBaseAmount        = GG_FPJVoucher_PPhBaseAmount.realValue();
                                GG_FPJVoucher2.FPJExchRate          = GG_FPJVoucher_FPJExchRate.realValue();
                                GG_FPJVoucher2.PPhExchRate          = GG_FPJVoucher_PPhExchRate.realValue();
                                GG_FPJVoucher2.FPJVoucherType       = GG_FPJVoucher_FPJVoucherType.selection();
                                GG_FPJVoucher2.SalesId              = GGSalesID.text();
                                GG_FPJVoucher2.VATPercent           = PPNPercent.realValue();
                                GG_FPJVoucher2.PPhPercent           = PPhPercent.realValue();
                                GG_FPJVoucher2.RetensiPercent       = RetensiPercent.realValue();
                                GG_FPJVoucher2.RetensiAmount        = RetensiAmount.realValue();
                                GG_FPJVoucher2.UangMuka             = Advance.value();

                                // added by adit
                                GG_FPJVoucher2.Retensi              = Retention.value();
                                GG_FPJVoucher2.BIT_Cash             = Cash.value();
                                GG_FPJVoucher2.BIT_Credit           = Credit.value();
                                GG_FPJVoucher2.BIT_KodePajak        = BIT_KodePajak.valueStr();
                                // ended by adit

                                GG_FPJVoucher2.AlocFPJNum           = OthFaktur.text();
                                GG_FPJVoucher2.Berikat              = Berikat.value();
                                //Breakpoint;
                                If ((Element.CreateFaktur(GG_FPJVoucher2.Voucher)) && ((GG_FPJVoucher2.VATPercent || GG_FPJVoucher2.PPhPercent) || Berikat.value()==NoYes::Yes))
                                    [GG_FPJVoucher2.AmountDPPFaktur, GG_FPJVoucher2.AmountPPNFaktur, GG_FPJVoucher2.AmountPPhFaktur]    = element.calculateAmountFakturTRY(GG_FPJVoucher2.Voucher, GG_FPJVoucher2.SalesId);
                                Else
                                    [GG_FPJVoucher2.AmountDPPFaktur, GG_FPJVoucher2.AmountPPNFaktur, GG_FPJVoucher2.AmountPPhFaktur]    = [0, 0, 0];

                                //Breakpoint;
                                IF ((GG_FPJVoucher2.AmountPPNFaktur > 0) && (GG_FPJVoucher2.AmountPPhFaktur == 0))
                                    GG_FPJVoucher2.Status       = GG_OpenClose::OpenVAT;

                                ELSE IF ((GG_FPJVoucher2.AmountPPNFaktur == 0) && (GG_FPJVoucher2.AmountPPhFaktur > 0))
                                {
                                    If (Berikat.value() != NoYes::Yes)
                                    GG_FPJVoucher2.Status       = GG_OpenClose::OpenPPh;
                                }
                                ELSE IF ((GG_FPJVoucher2.AmountPPNFaktur > 0) && (GG_FPJVoucher2.AmountPPhFaktur > 0))
                                    GG_FPJVoucher2.Status       = GG_OpenClose::Open;

                                ELSE IF ((GG_FPJVoucher2.AmountPPNFaktur == 0) && (GG_FPJVoucher2.AmountPPhFaktur == 0))
                                {
                                    GG_FPJVoucher2.Status       = GG_OpenClose::Closed;
                                }

                                If ((Berikat.value() == NoYes::Yes) && (GG_FPJVoucher2.AmountDPPFaktur != 0))
                                    GG_FPJVoucher2.Status       = GG_OpenClose::Open;

                                IF (SalesTable::find(GG_FPJVoucher2.SalesId).GGRetensi)
                                    GG_FPJVoucher2.calculateAmountFakturRetensi();

                                GG_FPJVoucher2.insert();
                                ttscommit;
                                info(strfmt("Data Inserted (Id : %1)", GG_FPJVoucher2.FPJVoucherId));
                                element.close();
                            }
                            catch
                            {
                                error("Process error");
                                ttsabort;
                            }

                        }
                        else
                            warning("Older Voucher date already exist in the same Customer account, please check transaction");
                    }
                    else
                    {
                        if(GG_FpjVoucher::FindVoucher(GG_FPJVoucher_Voucher.valueStr()).BIT_Batal == noyes::no)
                        {
                            info("Bukan Batal");
                            warning("Voucher Already Exist, Cannot Proceed !");
                        }
                    }





                }
            }
    else
        warning ("Cannot proceed, because PPNPercent for Berikat Customer, must be NULL");
    }
    else
        warning ("Cannot proceed because Voucher Amount is zero");
}

==========================================

// added by adit
// Order Quantity cannot more than Remain Quantity
public boolean validate()
{
    boolean ret;

    ret = super();
 
    if(SessionQty.valueStr() > remainQty.valueStr())
    {
ret = false;
        error("Order Quantity cannot more than Remain Quantity");      
    }

    return ret;
}

==============================================

0 comments:

A financial dimension value is based on the LAND-00013 record and has been used on a transaction. You cannot delete the LAND-00013 record AX 2012

 A financial dimension value is based on the LAND-00013 record and has been used on a  transaction. You cannot delete the LAND-00013 record ...