Wednesday, March 29, 2023

How to get vendor addresses in lookup

 internal final class DaxPurchTableForm_EventHandler

{            

/// <summary> 

/// </summary>    

/// <param name="sender"></param>      

/// /// <param name="e"></param>      

/// <summary>    ///    

/// </summary>    

/// <param name="sender"></param>    

/// <param name="e"></param>    

[FormControlEventHandler(formControlStr(PurchTable, PurchTable_Address), FormControlEventType::Lookup)]

    public static void PurchTable_Address_OnLookup(FormControl sender, FormControlEventArgs e)

    {        

PurchTable              purchTable;

        Query           query = new Query();

        QueryBuildDataSource    dsDirPartyPostalAddressView;

        FormRun                 formRun;

         formRun             =   sender.formRun();

         purchTable     = formRun.dataSource().cursor();

         // Instantiate sysTableLookup object using table which will provide the visible fields

          QueryBuildDataSource    qbds, qbds2, qbds3;

          QueryBuildDataSource    QbdsJoin;

          SysTableLookup          sysTableLookup =                  sysTableLookup::newParameters(tableNum(DirPartyPostalAddressView), sender);

          qbds = query.addDataSource(tableNum(DirPartyPostalAddressView));

          qbds.addGroupByField(fieldnum(DirPartyPostalAddressView, Address));

          qbds.orderMode(OrderMode::GroupBy);

          qbds2 = qbds.addDataSource(tableNum(vendtable));

          qbds2.addLink(fieldNum(DirPartyPostalAddressView, Party), fieldNum(VendTable, Party));

          qbds2.joinMode(JoinMode::ExistsJoin);

         qbds2.addRange(fieldNum(vendtable, AccountNum)).value(purchTable.OrderAccount);

          sysTableLookup.parmQuery(query);

          sysTableLookup.addLookupfield(fieldNum(DirPartyPostalAddressView, Address));

          sysTableLookup.performFormLookup();

         }

  }




....................................................................................................................................................................


How to get vendor location and tax name of vendor by selecting vendor address in lookup


 internal final class DaxPurchTableFormAddress_EventHandler
{       
 /// <summary>    ///    
/// </summary>    
/// <param name="sender"></param>    
/// <param name="e"></param>    
[FormControlEventHandler(formControlStr(PurchTable, PurchTable_Address), FormControlEventType::Modified)]
public static void PurchTable_Address_OnModified(FormControl sender, FormControlEventArgs e)
{        
VendTable               vendTable;
        PurchTable              purchTable;
        TaxInformation_IN       taxInformation_IN;
        LogisticsLocation       logisticsLocation;
        DirPartyTable           dirPartyTable;
        LogisticsPostalAddress  logisticsPostalAddress;
        Query           query = new Query();
        QueryBuildDataSource    queryBuildDataSource;
        QueryBuildRange         queryBuildRange;
        FormRun                 formRun;
         formRun = sender.formRun();
        FormDataSource purchtable_ds =  formRun.dataSource();
        purchTable     = formRun.dataSource().cursor();
          select logisticsPostalAddress where logisticsPostalAddress.Address == purchTable.Address;
        select logisticsLocation where logisticsLocation.RecId == logisticsPostalAddress.Location;
        select taxInformation_IN             
where taxInformation_IN.RegistrationLocation == logisticsLocation.RecId
            && taxInformation_IN.IsPrimary == NoYes::Yes;
          ttsbegin;
            purchTable.Name = taxInformation_IN.Name;
            purchTable.Description = logisticsLocation.Description;
            purchTable.selectForUpdate(true);
            purchTable.update();
        ttscommit;
    }
}




......................................................................................................................................

How to update the purchline vendor tax information based on selected vendor address.

My Requirement is to update the purchline vendor tax information. As in previous step select the address from lookup , a dialouge form should be opened. If user click ok address should be updated in purchline line of vendpor tax information. If  user click cancel it should not update.

[ExtensionOf(FormDataSourcestr(PurchTable,PurchTable))]
internal final class DaxPurchTableForm_Extension
{    
void  write()    
{        
PurchTable          purchTable;
        PurchLine           purchLine;
        VendTable           vendTable;
        TaxInformation_IN   taxInformation_IN;
        Dialog              dialog;
        TransTaxInformation transTaxInformationloc;
        DialogField         field;
        next write();
                purchTable = this.formRun().dataSource().cursor();
        FormDataSource purchTable_ds = this.formRun().dataSource();
        vendTable = VendTable::find(purchTable.OrderAccount);
        dialog = new Dialog("My Dialog");
        dialog.addText("Do you want to save");
        dialog.run();
            if (dialog.closedOk())
            {                
while select purchLine where purchLine.PurchId == purchTable.PurchId
                {
                    transTaxInformationloc = TransTaxInformationHelper_IN::findOrCreateTransTaxInformation(purchLine.TableId, purchLine.RecId);                   
                    if(transTaxInformationloc)
                    {
                        ttsbegin;
                        transTaxInformationloc.selectForUpdate(true);
                        TransTaxInformationHelper_IN::initFromCustVend(transTaxInformationloc, vendTable);
                        transTaxInformationloc.Update();
                        ttscommit;
                    }
                }
            }
    }
 }




..........................................................................................................................................

If new line created in purchline. A dialouge form should be opened, with ok and cancel buttons.

If user clicks ok, the updated address in purchaseorder header should be populated to current newly created line.If  user clicks cancel the purcline vendor tax information should be empty.


[ExtensionOf(formDataSourceStr(PurchTable,PurchLine))]
internal final class DaxPurchTable_Extension
{
    void  write()
    {
        PurchTable          purchTable;
        PurchLine           purchLine,purchLineloc,purchLineloc1;
        VendTable           vendTable;
        TaxInformation_IN   taxInformation_IN;
        Dialog              dialog;

        TransTaxInformation transTaxInformationloc;
        DialogField         field;
          next write();
         FormDataSource purchLine_ds = this.formRun().dataSource();
        purchLine = purchLine_ds.cursor();
        select purchTable where purchTable.PurchId == purchLine.PurchId;
        vendTable = VendTable::find(purchTable.OrderAccount);
        if(purchLine.RecId)
        {
        dialog = new Dialog("My Dialog");
        dialog.addText("Do you want to save");
        dialog.run();
        if (dialog.closedOk())
        {
                     transTaxInformationloc = TransTaxInformationHelper_IN::findOrCreateTransTaxInformation(purchLine.TableId, purchLine.RecId);
                if(transTaxInformationloc)
                {
                    ttsbegin;
                    transTaxInformationloc.selectForUpdate(true);                    TransTaxInformationHelper_IN::initFromCustVend(transTaxInformationloc, vendTable);
                    transTaxInformationloc.update();
                    ttscommit;
                }
        }
        else
         {
                       transTaxInformationloc = TransTaxInformationHelper_IN::findOrCreateTransTaxInformation(purchLine.TableId, purchLine.RecId);            if(transTaxInformationloc)
            {
                ttsbegin;
                transTaxInformationloc.selectForUpdate(true);
                transTaxInformationloc.VendorLocation =str2Int64("");
                transTaxInformationloc.VendorTaxInformation =str2Int64("");
                transTaxInformationloc.update();
                ttscommit;
            }
        }
        }
          
}  
}






Tuesday, March 14, 2023

How to generate a QR Code for SSRS report

 class QRHelper

{            

public static container QRCode(str _QRContents)

  {

    System.Drawing.Bitmap bm=null;

    try

   {  

  Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder qrCodeEncoder = new Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder();

    bm=qrCodeEncoder.Encode(_QRContents); 

   }                

catch(Exception::CLRError)                

 {                       

  error(CLRInterop::getLastException().toString());                              

 }                    

 using (var stream =new System.IO.MemoryStream())                    

{                            

bm.Save(stream,System.Drawing.Imaging.ImageFormat::Bmp);                            

bm.Dispose();                           

return Binary::constructFromMemoryStream(stream).getContainer();                   

}           

}  

}

.................................................................

Create a field container give EDT BITMAP

In DP class map the field with the above mentioned class as below :

Table.field =QRHelper::QRCode(string);


Wednesday, March 8, 2023

how to throw error for a invent journal line if selected item is not a supplementary item for main item of previous line

 [ExtensionOf(formDataSourceStr(InventJournalMovement,InventJournalTrans))]

public final class DaxInventJournalItemId_Extension

{    

/// <summary>    

///    /// </summary>    

/// <param name="sender"></param>    

/// <param name="e"></param>    

public boolean validateWrite()        

{

        InventJournalTable     inventJournalTable;

        InventJournalTrans     inventJournalTrans,inventJournalTrans1;

        SuppItemTable          suppItemTable;

        container              con;

        int                    i;

        boolean                ret;

           ret = next validateWrite();

          inventJournalTrans1 = this.cursor();

          select inventJournalTrans

            where inventJournalTrans.JournalId == inventJournalTrans1.JournalId;

        select * from suppItemTable

             where suppItemTable.ItemRelation == inventJournalTrans.ItemId

            && suppItemTable.SuppItemId == inventJournalTrans1.ItemId;

        if(!suppItemTable)

        {

            ret = Error("The selected Item is not Supply item");

        }              

return ret;

    }

  }


Thursday, March 2, 2023

How to update fixed asset dimensions values with the assigned purchase order dimension values

 public final class DaxtransferDimensionValues

{

    public static void main(Args args)

    {        

AssetTable          assetTable;

        AssetBook           assetBook;

        PurchTable          purchTable;

        RecordSortedList    assetBookList;

        DimensionDefault    defaultDimension;

        TransferDate        transferDate;

        TransferComment     transferComment;

        AssetTransfer       assetTransfer;               

assetTransfer = AssetTransfer::construct(); 

assetTable = args.record();           

        assetBookList = new RecordSortedList(tableNum(AssetBook));

        assetBookList.sortOrder(fieldNum(AssetTable, RecId));        

        transferDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());

        transferComment = "comment";

        select purchTable join assetBook 

           where purchTable.PurchId == assetBook.PurchId

            join assetTable where assetBook.AssetId == assetTable.AssetId;

        defaultDimension = purchTable.DefaultDimension;

        assetBookList.ins(assetBook);

        assetTransfer.transferAsset(assetBookList,defaultDimension,transferDate,transferComment);

     }  

}