Wednesday 28 November 2018

Sales order cannot be rearranged when included sales orders are tax regulated. Removed the regulation on the orders, rearrange and regulate the tax on the summary order dynamcis

Got below error while invoicing the sales order

Error:

Sales order cannot be rearranged when included sales orders are tax regulated. Removed the regulation on the orders, rearrange and regulate the tax on the summary order dynamics.


Reason: 

"override calculate sales tax" check box on sales order -> Sell -> Tax -> Sales tax -> Adjustment tab.

Solution:

-> Go to Sales order > Sell(tab) > Tax > SalesTax
2. Click on the "Adjustment" tab
3. Click on the "Reset actual to calculated amounts" and close the form
4. Proceed to invoice and post invoice. 

@Rahul

Monday 26 November 2018

Method Sequences while opening form in AX 2012 / AX 7 / D365 F&O


User actions on a form are input through mouse pointers and keyboards. These actions cause events that are recognized by Microsoft Dynamics AX. The recognized events include the following:
The system reacts to each event by executing several event methods. The user is often unaware that these methods are being executed.

Customize the Responses to User Events

Use the Application Object Tree (AOT) to override the event methods and customize the response to form events.
  1. Expand the Forms node to see its Methods subnode.
  2. Expand the Methods node to see a subnode for each method that is currently overridden.
  3. Right-click the Methods node, and then select Override Method to see a list of methods that have not yet been overridden.
  4. Expand other nodes under Forms to see additional Methods nodes.

Use Sequence Information to Determine the Correct Method to Override

Information about the sequence of event method execution is useful when you are determining the correct method to override. For example, you could write code to log the inserts that the user causes when they enter data into a grid control. This code could be placed in various event methods. You could override the insert event method on an underlying table. By knowing the aosValidateInsert method is executed immediately after the insert method, you might instead choose to log the aosValidateInsert method. Overriding aosValidateInsert might provide log information that has the results of security checks.

Open a Form

In this example, the user opens a form that contains a grid control, which is bound to a data source.
The executed events are distributed across two threads. The timing of event method execution between threads can vary.
The following table shows the sequence that event methods are executed in when a user opens a form.
Method
Where
Thread number
new
Form
init
Form
1
loadUserSetting
Form
2
run
Form
1
init
Data source
2
executeQuery
Data source
2
leaveRecord
Data source
2
leave
Data source
2
leaveRecord
Data source
2
firstField
Form
2
firstField
Form
1


Most forms in Microsoft Dynamics AX are closed when a user clicks the Close button (the standard button in the upper-right corner of most windows). Some forms can be closed by clicking either an OK or a Cancel button. When the form is closed, event methods are executed.

Close the Form by Using the Cancel Button

When a user closes a form by clicking the Cancel button, event methods are executed in the following sequence:
  1. closeCancel on the form.
  2. canClose on the form.
  3. close on the form.
 Note
The FormRun class has the closed method and the closedCancel method. These event methods are not executed when the Cancel button is clicked.
When a form is closed with the closeCancel event method, the user's changes are not saved.

Scenario

This scenario uses a form that contains one CheckBox control as its only control. Assume that the CheckBox control is bound to a form's data source and that the control can update the data source.

Aa602745.collapse_all(en-us,AX.60).gifClose the Form by Using the Close Button

When a user closes a form by clicking the Close button, event methods are executed in the sequence shown in the following lists. These lists are based on the previous scenario.
Following is the sequence of event methods when the form is closed—without the user clicking the check box.
  1. canClose on the form.
  2. leave on the check box.
  3. leave on the check box.
  4. leave on the data source.
  5. leaveValidate on the data source.
  6. leave on the check box.
  7. leave on the check box.
  8. close on the form.
  9. saveUserSetting on the form.
Following is the sequence of event methods when the form is closed—after the user has clicked a check box.
  1. canClose on the form.
  2. leave on the check box.
  3. leave on the check box.
  4. validateWrite on the data source.
  5. Write on the data source.
  6. update on the table.
  7. leaveRecord on the data source.
  8. leave on the data source.
  9. leaveRecord on the data source.
  10. leave on the check box.
  11. leave on the check box.
  12. close on the form.
  13. saveUserSetting on the form.

Aa602745.collapse_all(en-us,AX.60).gifClose the Form by Using the OK Button

Some forms can be closed by clicking an OK button. This leads to almost the same event method sequence as shown in the Close the Form by Using the Close Button section. The only difference is that clicking the OK button causes the Form.closeOK event method to be executed first.

Event methods are executed when the value of a control changes. The exact sequence of event methods varies for different controls.

Check Box Scenario

The example scenario uses a simple form that has a check box control. The check box is bound to a field in a data source.
A check box is a control that has a value property. In contrast, a grid control contains fields that each display a value, but the grid itself does not have a value property.

Aa642643.collapse_all(en-us,AX.60).gifClick to Change the Value in a Check Box

The following sequence of event methods is executed when the check box is either selected or cleared by a user.
  1. validate on the check box.
  2. modified on the check box.
  3. validateField on the table.

Aa642643.collapse_all(en-us,AX.60).gifRemove Focus from a Check Box

The following event method is the only one executed when focus is removed from the check box:
  • leave on the check box.


An event method sequence is executed when focus is removed from a record. The sequence includes the leaveRecord method. Form controls that simultaneously display multiple records have the leaveRecord event method.

Grid Scenario

This scenario has a form that contains a grid control, which is bound to a data source. The form is open, and the grid is populated with data. Focus is on the first line of the grid.

Aa628445.collapse_all(en-us,AX.60).gifMove Focus from one Record to Another

Without changing any data, the user clicks a different grid line to move focus to that line. The following event method sequence is executed when data in the first line is unchanged.
  1. leave on the data source.
  2. leaveRecord on the data source.
A longer event method sequence occurs when grid line data changes before focus is moved from that grid line.
  1. modifiedField on the table.
  2. update on the table.
  3. aosValidateUpdate on the table.
  4. leaveRecord on the data source.
  5. leave on the data source.
  6. leaveRecord on the data source.


An event method sequence is executed when a record is deleted from a grid control. The grid control is on a form.

Grid Scenario

This scenario has a form that contains a grid control, which is bound to a data source. The data source is associated with a table. The form is open and the grid is populated. Focus is on the first line of the grid.
The user presses ALT+F9 to delete the record, and then clicks Yes to confirm. The following event methods are executed in response to that event.
  1. validateDelete on the table.
  2. delete on the table.
  3. aosValidateDelete on the table.
  4. leaveRecord on the data source.

Event methods are executed when a form is used to create a new record. The details can vary, depending on the type of controls present on the form.

Grid Scenario

In this scenario, a form contains one grid control. A data source is bound to the grid control. The data source is associated with two fields from a table.
A user opens the form, and then the grid is populated with data. The first line in the grid has focus.

Aa592877.collapse_all(en-us,AX.60).gifA User Creates a Record

A user enters a new record by using a grid control on a form. They begin by pressing the shortcut keys CTRL+N. This creates a new, empty line in the grid and gives focus to the new line. The following list shows the sequence of event method executions that occurs when the user continues with the steps needed to create a record in the database.
  1. leaveRecord on the data source.
    The user enters data into the first empty cell, and then presses TAB.
  2. validateField on the table.
  3. modifiedField on the table.
    The user now enters data into the second empty cell. They click a grid line that is already populated to take focus from the new line.
  4. validateField on the table.
  5. modifiedField on the table.
  6. validateWrite on the table.
  7. insert on the table.
  8. aosValidateInsert on the table.
  9. leaveRecord on the data source.
  10. leave on the data source.
  11. leaveRecord on the data source.

Remove reservations and markings from a sales orders in Ax 2012/ D365 F&O x++



Below is the code where we can unreserve the inventory from sales orders/sales order lines.

Paste the below in a JOB

Static void Tutorial_UnreserveSalesTable(Args _args) { InventTrans inventTrans; InventTransOrigin inventTransOrigin; SalesLine salesLine; InventMovement inventMovement; InventUpd_Reservation inventUpd_Reservation ; SalesId SalesId = "001260";//<--- Send/get sales id here // Remove reservations and markings on a reserved salesorder while select inventTrans where inventTrans.StatusReceipt == StatusReceipt::None && (inventTrans.StatusIssue == StatusIssue::ReservPhysical || inventTrans.StatusIssue == StatusIssue::ReservOrdered) exists join inventTransOrigin where inventTransOrigin.RecId == inventTrans.InventTransOrigin exists join salesLine where salesLine.InventTransId == inventTransOrigin.InventTransId && SalesLine.SalesId == SalesId { if (inventTrans.MarkingRefInventTransOrigin) { InventTransOrigin::deleteMarking(inventTrans.MarkingRefInventTransOrigin, inventTrans.InventTransOrigin, -inventTrans.Qty, true); InventTransOrigin::deleteMarking(inventTrans.InventTransOrigin, inventTrans.MarkingRefInventTransOrigin, inventTrans.Qty, true); } if (inventTrans.StatusIssue == StatusIssue::ReservPhysical || inventTrans.StatusIssue == StatusIssue::ReservOrdered) { Inventmovement = inventTrans.inventmovement(true); inventUpd_Reservation = InventUpd_Reservation::newInventDim(inventmovement,inventTrans.inventDim(), -1 * inventTrans.Qty, false); inventUpd_Reservation.updatenow(); } } }


@Rahul

Monday 12 November 2018

How to get sales order totals in D365 F&O/ AX 7 x++

Below is the the piece code we can use for getting the sales order totals.

class SW_CST_Tableid2name
{       
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {   
        SalesTotals salesTotals;
        SalesTable salesTable;
        SalesLine salesLine;

        TaxAmountCur salesAmt,taxAmount,amt1,discountAmt,totcharges,totOfOrder,contributionRatio;
        Tax tax;

        ;
        salesTable = SalesTable::find("SO00094903");
        salesLine = SalesLine::find(salesTable.SalesId);
        salesTotals = SalesTotals::construct(salesTable, SalesUpdate::All);
        tax = Tax::construct(NoYes::No);

        salesAmt    = salesTotals.totalBalance();
        taxAmount   = salesTotals.totalTaxAmount();
        discountAmt = salesTotals.totalEndDisc();
        totcharges  = salesTotals.totalMarkup();
        totOfOrder  = salesTotals.totalAmount();
        //contributionRatio   = salesTotals.totalContributionRatio();

        info(Strfmt("Subtotal Amount %1",salesAmt ));
        info(Strfmt("The tax amount is %1",taxAmount ));
        info(Strfmt("The Discount is %1",discountAmt ));
        info(Strfmt("Charges/ Markup %1",totcharges ));
        info(Strfmt("Invoice Amount %1",totOfOrder ));
        info(Strfmt("Contribution ratio %1",contributionRatio ));
    }

}

Friday 2 November 2018

The working folder C:\Users\Adminab12363\Documents\Visual Studio 2015\Projects is already in use by the workspace dev669312-1;oldaccount@xyz.com on computer dev669312-1.

Hi Guys,

I got the below error while I was trying to create a new workspace  for my new account.

The working folder C:\Users\Adminab12363\Documents\Visual Studio 2015\Projects is already in use by the workspace dev669312-1;oldaccount@xyz.com on computer dev669312-1.


Reason: Multiple workspaces bounded.  

Solution: In my case I deleted my old account workspace by using command prompt.

-> Go to  C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
open command prompt as an admin.




Follow the syntax
tf workspace /delete "WORKSPACENAME;PREVIOUSUSERACCOUNT”


copy and paste in the command prompt and hit enter, then select "Y".

tf workspace /delete "SBIN001-3;rahulax@xyz.com"

Delete workspace of another user in Visual studio 2015 TFS

Hi Guys,

Here I'm showing yow how to delete a workspace of a user in Visual studio.

-> Go to  C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
open command prompt as an admin.




Follow the syntax
tf workspace /delete "WORKSPACENAME;PREVIOUSUSERACCOUNT”


copy and paste in the command prompt and hit enter, then select "Y".

tf workspace /delete "SBIN001-3;rahulax@xyz.com"


That's it.

Adding a newline into a string in C# and X++

Below is the sample code we can use for  adding a newline after every occurrence of "@" symbol in the string in C#   using System...