Total Pageviews

Showing posts with label Dynamics Ax. Show all posts
Showing posts with label Dynamics Ax. Show all posts

Friday, March 21, 2025

Preventing Price Recalculation for Imported Sales Lines ( custom price other then trade agreements price) in D365FO - X++ - Microsoft Dynamics 365 Finance & operations

 In D365FO if sales line is imported from excel using custom built solution or sales line is created from Code X++ and user provide its own unit price (price other then trade agreements) after sales line creation user go to sales order and click Recalculate and update the Unit price as per trade agreement. To stop this behavior (stop recalculation) if price is enter manually or is custom price is imported for sales line

need to add below code after you modify price in code 


Salesline.setPriceDiscChangePolicy(PriceDiscSystemSource::ManualEntry, fieldNum(Salesline, SalesPrice));

it will stop recalculating price for particuallar sales line when some one click Recalculate button on sales order 

Thursday, January 30, 2020

D365FO. Dynamics 365 fiance and operation. Get and update contract of batch job on Controller run method. ax 2012

set Batch id in contract if batch isInBatch check is true

in run method we will update the contract and set the batch id.


class BrFunctionalLocationRecordsController extends SysOperationServiceController
{
    protected void new()
    {
        super(classStr(BrFunctionalLocationRecordsService), methodStr(BrFunctionalLocationRecordsService, functionalLocationRecordsService), SysOperationExecutionMode::Synchronous);
    }

 
    public static BrFunctionalLocationRecordsController construct(SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Synchronous)
    {
        BrFunctionalLocationRecordsController      controller;
        controller = new BrFunctionalLocationRecordsController();
        controller.parmExecutionMode(_executionMode);
        return controller;
    }

 
    public static void main(Args _args)
    {
        BrFunctionalLocationRecordsController controller;
        // to update contract value at main we can initialize contract here.
        //BrFunctionalLocationRecordsContract   brFunctionalLocationRecordsContract;

        controller = BrFunctionalLocationRecordsController::construct();
        //and can set contract values here
        //brFunctionalLocationRecordsContract = controller.getDataContractObject();
        controller.parmArgs(_args);
        controller.startOperation();
    }

 
    public ClassDescription defaultCaption()
    {
        return "@Br:FunctionalLocationRecords";
    }

   
    public void run()
    {
        BrFunctionalLocationRecordsContract brFunctionalLocationRecordsContract;

       //getting batch contract.
        brFunctionalLocationRecordsContract = this.getDataContractObject();
       
        Batch                                   batch;
        if (this.isInBatch())
        {
            //getting batch information;
            batch = this.currentBatch;
            //setting batch id in contract
            brFunctionalLocationRecordsContract.parmBatchHeader(batch.BatchJobId);
        }
        super();
    }

}

Thursday, December 7, 2017

Creating Payment journal and posting Payment journal ax2012 /D365 ax7 x++

Public static boolean processPayment(BAModule BAModule)
{
ledgerJournalName  JournalName ;
ledgerJournalCheckPost JournalCheckPost;

ledgerJournalTable JournalTable;
ledgerJournalTrans JournalTrans;
JournalCheckPost JournalCheckPost;

Common common;
NumberSeq numberseq;
CustTrans custTrans;
CustTransOpen custTransOpen;
Specification specOffsetVoucher;

BAParameters parameters = BAParameters::find();
CustTable custTable = CustTable::find(BAModule.CustAccount);
boolean return = false;
InvoiceId invoiceId;
;

while select custTransOpen
where custTransOpen.RefRecIdCheck == BaModule.RecId &&
custTransOpen.UseRefRecId
{
custTrans = custTransOpen.custTrans();
invoiceId = custTrans.Invoice;

try
{
ttsbegin;

select firstonly JournalName
where JournalName .JournalName == parameters.JournalName Id &&
JournalName .JournalType == LedgerJournalType::CustPayment;

if(!JournalName .RecId)
throw error("@11250");

if(JournalName )
{
JournalTable.JournalName = JournalName .JournalName;
JournalTable.Name = JournalName .Name;
JournalTable.insert();

if(JournalTable)
{
numberseq = NumberSeq::NewGetVoucherFromCode(JournalName .VoucherSeries);
JournalTrans.JournalNum = JournalTable.JournalNum;
JournalTrans.Voucher = numberseq.voucher();
JournalTrans.TransDate = today();
JournalTrans.Txt = CustTable::find(JournalTrans.AccountNum).Name;
JournalTrans.OffsetAccountType = JournalName .OffsetAccountType;
JournalTrans.OffsetAccount = JournalName .OffsetAccount;
JournalTrans.Dimension = JournalName .Dimension;
JournalTrans.CurrencyCode = JournalTable.CurrencyCode;
JournalTrans.AccountType = LedgerJournalACType::Cust;

JournalTrans.TransactionType = LedgerTransType::Payment;
JournalTrans.PaymMode = parameters.PaymMode;
JournalTrans.SettleVoucher = SettlementType::SelectedTransact;
JournalTrans.AccountNum = custTable.AccountNum;
JournalTrans.AmountCurCredit = custTransOpen.AmountCur;
JournalTrans.ExchRate = ExchRates::find(JournalTable.CurrencyCode, datenull(), NoYes::No, NoYes::No).ExchRate;
JournalTrans.insert();

select custTransOpen
where custTransOpen.AccountNum == custTable.AccountNum &&
custTransOpen.RefRecId == CustTrans::findFromInvoice(invoiceId).RecId;

if(custTransOpen)
{
common = JournalTrans;
specOffsetVoucher = Specification_OffsetVoucher::newCommon(common, true);
if (!specOffsetVoucher.isMarked(custTransOpen.TableId, custTransOpen.RecId))
if (JournalTrans.RecId)
specOffsetVoucher.create(custTransOpen.TableId, custTransOpen.RecId, custTransOpen.AmountCur, JournalTable.CurrencyCode);
}

JournalCheckPost = JournalCheckPost::newJournalTable(JournalTable, NoYes::Yes);
JournalCheckPost.run();
return = true;
}
}
ttscommit;
}
catch
{
ttsabort;
return = false;
}
}
return return;
}

Friday, November 24, 2017

Creating a Valid Time State Table/Maintaining ValidTimeState Record


Maintaining Version of table record
Step 1)
Create Table Name: TableA and add fields to tha table

Note : You can change the ValidTimeStateFieldType to any value when the table contains no data. You can change the value to None even if the table contains data.

Step 2) go to table properties and set following properties          

Now Valid to valid from fields are added to your table automatically

Step 3 ) Create index and go to properties and set following properties

At least 3 fields will be added to index valid to, valid form and one other field (like accountNum as shown in table)

Note : You can change the ValidTimeStateMode property from Gap to NoGap only if the table contains no data. You can change from NoGapto Gap even if the table contains data.






Friday, March 10, 2017

mark/unmark checkbox Dynamics ax tree node on click




mark/unmark checkbox Dynamics ax tree node on click



public int mouseDown(int _x, int _y, int _button, boolean _Ctrl, boolean _Shift)
{
    ImageRes     stateImage;
    int idx,f;
    int ret;

    FormTreeItem formTreeItem ;
    FormTreeItem        parentNode;
     #FormTreeControl
    [idx,f]      = this.hitTest(_x,_y);

    FormTreeItem = this.getItem(idx);
    ret = super(_x, _y, _button, _Ctrl, _Shift);
    if (FormTreeItem)

    {
      switch(formTreeItem.stateImage())
     {
        case imageListAppl_checkbox.image(#ImageCheckNone):
        stateImage = imageListAppl_checkbox.image(#ImageCheckAll);
        formTreeItem.stateImage(stateImage);
        this.setItem(formTreeItem);
       
         break;
        case imageListAppl_checkbox.image(#ImageCheckAll):
        stateImage = imageListAppl_checkbox.image(#ImageCheckNone);
        formTreeItem.stateImage(stateImage);
        this.setItem(formTreeItem);
        
        break;
      }
   }
   Return ret;

}

iterate all tree nodes and set check box Dynamics Ax 2012

Public void setCheckbox()
{
    TreeItemIdx                         treeItemIdxOU,treeItemIdxChild;
    FormTreeItem                        formTreeItem,selectedTreeItem;
    Map en = new Map(Types::Integer,Types::Int64) ;
    MapEnumerator   me;
    int childcount=1;
    ImageRes     stateImage;
    ListEnumerator listEnumrOU, listEnumr;
    imageListAppl_checkbox = new ImageListAppl_checkbox();



    treeItemIdxOU = ResourceGroupTree.getChild(ResourceGroupTree.getRoot());
    en.insert(childcount,treeItemIdxOU);
    while (treeItemIdxOU)
    {
       if(ResourceGroupTree.getNextSibling(treeItemIdxOU))
        {
           childcount++;
           treeItemIdxOU =  ResourceGroupTree.getNextSibling(treeItemIdxOU);
           en.insert(childcount, treeItemIdxOU);
        }
        else
        {
            break;
        }
    }
    me = en.getEnumerator();
    while(me.moveNext())
    {
        if(ResourceGroupTree.getChild(me.currentValue()))
        {
            treeItemIdxChild = ResourceGroupTree.getChild(me.currentValue());
            ResourceGroupTree.setStateImagelist(imageListAppl_checkbox.imageList());
            formTreeItem = ResourceGroupTree.getItem(treeItemIdxChild);
            stateImage = imageListAppl_checkbox.image(#ImageCheckNone);
            formTreeItem.stateImage(stateImage);
            ResourceGroupTree.setItem(formTreeItem);
            
        }
        while(treeItemIdxChild)
        {
            if(ResourceGroupTree.getNextSibling(treeItemIdxChild))
            {
                treeItemIdxChild = ResourceGroupTree.getNextSibling(treeItemIdxChild);
                ResourceGroupTree.setStateImagelist(imageListAppl_checkbox.imageList());
                formTreeItem = ResourceGroupTree.getItem(treeItemIdxChild);
                stateImage = imageListAppl_checkbox.image(#ImageCheckNone);
                formTreeItem.stateImage(stateImage);
                ResourceGroupTree.setItem(formTreeItem);
               
            }
            else
            {
                break;
            }
        }
       // me.moveNext();

    }
}


pass args/table to class main method using action menuitem button

  • create new class 


class newclass
{

}
public static void main(Args _args)
{
     #Task
    FormDataSource fds;
    FormRun        formrun=_args.caller();
    Str      Postion;   
  fds = _args.record().dataSource();
try
    {

        ttsBegin;

        for (smmActivities = fds.getFirst(true) ? fds.getFirst(true) : fds.cursor(); smmActivities; smmActivities = fds.getNext())
        {
            smmActivitiesUpdate = smmActivities::find(smmActivities.ActivityNumber, true);
            if(smmactivitiesUpdate.EnumYesnoField == NoYes::Yes)// check if field is already yes then throw warning
            {
                ttsAbort;
                ret = false;
                throw warning("already yes");
            }
            else
            {
                Position = smmActivitiesUpdate.ActivityNumber;
                smmactivitiesUpdate.EnumYesnoField =NoYes::Yes;
                smmactivitiesUpdate.update();
            }
        }
        ttsCommit;
        ret = true;
        if(formrun)
        {
            formrun.task(#taskF5);
            fds.findRecord(smmActivities::find(Position));
        }

    }
    catch
    {
        ret = false;
    }


  •  Add action menu item to form 
  • set data source to smmActivities 


D365FO and Sharepoint integration issue on dev box: "You are not authorized to connect to 'https://sharepoint.sharepoint.com/

Troubleshooting SharePoint Integration After Upgrading D365FO to Version .42 After upgrading to Dynamics 365 Finance and Operations (D365FO)...