Monday, October 29, 2018

Sending Email using X++ Code in D365 F&O/ AX 7

I was just researching on the emailing capabilities in D365 and found that SysINetMail, SysMailer and some of the smmOutlook classes are deprecated because these classes used predominantly client-side technologies that are no longer available
Below is the quick code snippet that can be used in D365 to send emails. Please note, this is just a untested sample code, with out any setups configured. please ensure all setups are done and improvise the code accordingly.
SysMailerFactory class internally used SysImailer* classes to send emails.
class SRSendEmail_D365
{       
    public static void main(Args _args)
    {  
        SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();
        Email   toEmail;
        Email   fromEmail;
         
        try
        {
            FromEmail = "fromemail@xyzcompany.com";
            toEmail   = "oemail@xyzcompany.com";

            messageBuilder.setBody("Hello from D365", false);
            messageBuilder.setSubject("Email Test from D365");
            messageBuilder.addTo(toEmail);
            // Note: not calling setFrom() defaults to the current user for SMTP client, whereas
            // when sent to Outlook any setFrom() value will be ignored since profiles on the client are used
            messageBuilder.setFrom(fromEmail);

            // Open the generated email in the configured client
            // Sends a message interactively, allowing the user to view and modify the message before
            SysMailerFactory::sendInteractive(messageBuilder.getMessage());
            // Try using sendNonInteractive method too
        }
        catch (Exception::Error)
        {
            throw error("@SYS33567");
        }
    }

}

Context Menus in D365 F&O

In older versions of AX, We used right-click context menus (shortcut menus) by using the PopupMenu class
But in the current version, this can be achieved by using ContextMenu API and by overriding 2 methods getContextMenuOptions(), to add options to the context menu and selectedMenuOption() to process the user’s selection
Lets create a new form as shown below by name SRContextMenu. I have added CustGroup Table as a dataSource and in the design I have added CustGroup control to the grid.

image
Lets see the coding part to achieve this now. Override the classDeclaration method of the form/element and add the below line of code
[Form]
public class SRContextMenu extends FormRun
{
    public const int rootIdx = 1;
}
Then override the getContextMenuOptions method as shown below from the CustGroup control
image
Add the below lines of code in the method. In the below example, I am adding a new new context menu option with the label – “Get customer balance(s )”
[Control("String")]
    class CustGroup_CustGroup
    {
        public str getContextMenuOptions()
        {
            str ret;
            ContextMenu menu = new ContextMenu();
            ContextMenuOption option = ContextMenuOption::Create("Get customer balance(s)", rootIdx);
            List menuOptions = new List(Types::Class);
            // Add label and ID of menu option
            menuOptions.addEnd(option);
            menu.ContextMenuOptions(menuOptions);
            return menu.Serialize();
        }

    }
Next override the selectedMenuOption() method as shown below from the CustGroup control
image
Add the below lines of code to Process the user selection from the context menu
// Define new override on the control for processing the user selection
        public void selectedMenuOption(int selectedOption)
        {
            CustTable custTable;
            AmountCur  balanceAmt;

            switch (selectedOption)
            {
                case –1:
                    break;
                case rootIdx:
                    while select CustTable where CustTable.CustGroup == CustGroup.CustGroup
                    {
                        balanceAmt += CustTable.balanceMST();
                    }
                    info(strFmt("%1", balanceAmt));
                    break;
                default:
                    break;
            }
        }
Now, lets open the form and see the newly added Context menu option. Right click on the customer group control in the grid and you will find our newly created option as shown below.

image
Double click on the option and it will process the context menu option. In this example, I am showing all the customer balances of that particular customer group in the Infolog
image
Some guidelines before using context menus

 

  • The most important commands should be at the top of the menu.
  • Remove commands that don’t apply to the current state of the element that is the target of the right-click.
  • Right-click is a shortcut. Therefore, the commands on the context menu should always be available in other places on the page.
  • Don’t create submenus of context menus. Submenus are hard to use and aren’t touch-friendly.
  • Limit the number of menu items to five.

How to cancel a registered return order in D365 F&O / AX 2012

Remove the disposition code from lines and the cancel option will be returned to you. The disposition code moves it to an open status removing the cancel option. By entering the disposition code it is an indication you have received the stock.

If you don't see disposition code in the line level, go to personalization and add the field.

Then go to the header and cancel the return order.


@Rahul😊

Sort / Order a container in ASC order in AX 7 / D365 F&O X++

Below is the job which will help for sorting the values in a container. 
static void SortContainer(Args _args)
{
container con = [5,1,2,"Rahul",9, "Kiran", NoYes::No];
str temp1;
str temp2;
int i;
int j;
container sorCon;
;
sorCon = con;
// Sort the container
for (i = 1; i <= conlen(sorCon); i++)
{
for (j = i + 1; j <= conlen(sorCon); j++)
{
temp1 = conpeek(sorCon, j);
temp2 = conpeek(sorCon, i);
if (temp1 < temp2)
{
sorCon = condel(sorCon, j, 1);
sorCon = conins(sorCon, j, temp2);
sorCon = condel(sorCon, i, 1);
sorCon = conins(sorCon, i, temp1);
}
}
}

conview(sorCon);
}

Wednesday, October 17, 2018

SysIntegrationActivityBatchTask-run. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Could not find default endpoint element that references contract 'Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelperService.Contract.ServiceContract' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

Hi,

I got the below error while trying to export the files from data management module.

Reason: Mostly we face this issue when the environment is newly is setup.

SysIntegrationActivityBatchTask-run. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Could not find default endpoint element that references contract 'Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelperService.Contract.ServiceContract' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
   at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
   at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
   at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address, Configuration configuration)
   at System.ServiceModel.Configuration.ConfigurationChannelFactory`1..ctor(String endpointConfigurationName, Configuration configuration, EndpointAddress remoteAddress)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at Microsoft.Dynamics.IntegrationFramework.ServiceReference.GetServiceEndpoint(Type serviceClientType, String configFilePath)
   at Microsoft.Dynamics.IntegrationFramework.ServiceReference.CreateServiceClient(Type serviceClientType, String configFilePath)
   at Dynamics.AX.Application.DMFParameters.createWebServiceClient(Object serviceClientType) in xppSource://Source/ApplicationFoundation\AxTable_DMFParameters.xpp:line 291
   at Dynamics.AX.Application.DMFParameters.createServiceClient(Object serviceClientType) in xppSource://Source/ApplicationFoundation\AxTable_DMFParameters.xpp:line 266
   at Dynamics.AX.Application.DMFGenerateSSISPackage.generateFileData(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution, String _defGroupName, DMFFileFormat _fileFormat, DMFDelimiter _rowDelimiter, DMFDelimiter _columnDelimiter, String _codePage, String _locale, NoYes _isFirstRowHeader, NoYes _unicode, String _source, String _textQualifier, DMFXMLStyle _style, String _rootElement, String _filePath) in xppSource://Source/ApplicationFoundation\AxClass_DMFGenerateSSISPackage.xpp:line 996



Solution: Please refer below post.
http://rahulmsdax.blogspot.com/2018/08/systemreflectiontargetinvocationexcepti.html?showComment=1535477574484

Tuesday, September 11, 2018

The inventory unit for item cannot be changed because activated cost prices exist. The cost prices can only be deleted by deleting the item.

Getting the below error while trying to add the inventory unit.

Error:
The inventory unit for item cannot be changed because activated coset prices exist. The cost prices can only be deleted by deleting the item.

Reason:
Item price was posted for the item. That's the reason AX is not allowing to modify the item.

Solution:
In my case I deleted the item and recreated it again.

Tuesday, September 4, 2018

Cannot create a record in Price history(MCRPriceHistory). Price/discount type: Item price, The record already exists.

I got the below error while trying to upload/creating the sales orders.

Cannot create a record in Price history(MCRPriceHistory). Price/discount type: Item price,
The record already exists.


Solution:

Change the Next number for the price/discount in number sequence.
In my case the next number was 1066 and I changed it to 1067

To find the number sequence.
Accounts receivable > accounts receivable parameters > Number sequence > price/discount journal number.

What is the primary purpose of using a Solution in Microsoft Power Platform & ALM?

As organizations embrace low-code development with Microsoft Power Platform , it becomes essential to manage and govern apps, flows, and dat...