Sunday, December 27, 2020

Setting up alert on specific batch job in case of Error or canceled in Dynamics 365 finance and operations

Alerts are very important events for business and can be created to notify user based on the change. As everyone aware we can setup alert when create , update or delete actions performed on a record or specific field. but we can setup a alert for specific batch job in the system when it Ended , Failed or Cancelled. 

This can be done at the time of setting of the batch job.

Scenario:- 

We have a customer scenario where business user has to be notified when ever "Batch job history clean-up" job end with error or cancelled. 

Steps to configure:- 

1. Go to System Administrator > Periodic tasks >  Batch job history clean-up


























2. If you expand the run in the background section then we can see two options, Recurrence and Alerts. 







































3. Then click on Alerts and setup the events you want alerts to be triggered and click on ok 
4. In this case user fill get notified in the action center when ever the batch job "Batch job history clean-up" ended with error or canceled.
The same alert can be send as email but for that smtp server should be configured in email parameters.



Please note if you want to get alert then "Change based alerts" batch job should be running every min. 

Hope you find this useful and will come up with another interesting blog






Convert Electronic Reporting outbound documents from Microsoft Office formats to PDF in Dynamics 365 finance and operations

 As we aware new feature has been introduced in feature management in Dynamics 365 finance and operations with powerful features. but these features has been not enabled by default. 

Recently we have received a power full feature which coverts all electronic reporting outbound documents from Microsoft Office formats to PDF in Dynamics 365 finance and operations.

Go to System administration > Workspaces > Feature management and enable "Convert Electronic Reporting outbound documents from Microsoft Office formats to PDF" feature




Once we enable this then if you go back to Electronic reporting destination settings, we can see Convert to PDF checkbox enabled.

If you check this checkbox then document will be converted to PDF before we export.












Hope you find this useful and will come up with another interesting blog










Monday, December 21, 2020

Get default dimension name and description in Dynamics 365 finance and operations

I had requirement to get default dimension for Main account and when I look at internet I could see all of them  are so complex to get dimension name and description especially description. 

In fact we don't need all of them because in out of the box we have view which gives all this info by just one select query. if we have Default dimension and dimension. 


This view has method DefaultDimensionView.dimensionDiscription() which gives dimension description.

Please code for your reference, hope you find this useful!  

public static void main(Args _args)

    {

        #define.DimensionName("Department");

        DefaultDimensionView DefaultDimensionView;


        select firstonly DefaultDimensionView

             where DefaultDimensionView.Name == #DimensionName

                && DefaultDimensionView.DefaultDimension == 5637451520;//RecId of default dimension


        info(strFmt('Dimension Name: %1, Dimension description:%2', DefaultDimensionView.DisplayValue, DefaultDimensionView.dimensionDiscription()));

    }



Error settlement of Payments after removing AMC banking ISV solution.

 Our client uses AMC banking ISV solution for past 3 year and now they thought to quite and use existing features in out of the box with few customizations in case of out going payments as well as incoming payments. 

For outgoing payments we have "MultiCash (PL)" but its text file but client required in "ISO 20022 credit transfer", hence we have derived standard format and built new. 

For incoming payments we have used  "ISO20022 camt.054" and for advance bank reconciliation we have used "ISO20022 camt.053" with few minor changes in format and model mapping.

Everything was fine but finally we had an issue with settlement of customer or vendor payments. all the open transactions marked as "In use", hence we are not able to settle any transactions.

and we don't see any pending customer / vendor payment journals in the system. 

As everyone aware we need to remove reference in SpecTrans table hence I have built following script, may be you can find it useful if you face similar issues.

Once we ran this script then we are able to settle all the transactions which are struck in use.

public void clicked()

{

            SpecTrans       specTrans;

            CustTransOpen   custTransOpen;

            VendTransOpen   vendTransOpen;

            CustTrans       custTrans;

            VendTrans       vendTrans;

            container       conCustInvoice, conVendInvoice;

            int             totalCustInvoices, totalVendInvoices;


            if(Box::yesNo('@JP:DeleteAllSpecTransForPoland', DialogButton::Yes) == DialogButton::Yes)

            {

                changecompany('<Legal Entity>')

                {

                    ttsbegin;

                    while select specTrans join custTransOpen

                        where CustTransOpen.DataAreaId == specTrans.RefCompany

                        && CustTransOpen.RecId == specTrans.RefRecId

                        && CustTransOpen.TableId == specTrans.RefTableId

                        join custTrans

                        where custTrans.RecId == custTransOpen.RefRecId

                        && custTrans.AccountNum == custTrans.AccountNum

                    {

                        if (!conFind(conCustInvoice, custTrans.Invoice))

                        {

                            conCustInvoice += custTrans.Invoice;

                            

                        }

                        totalCustInvoices++;

                    }


                    info(con2Str(conCustInvoice));

                    info(strFmt('@JP:TotalSpecTransRecordsDeletedForCustomer', totalCustInvoices));


                    specTrans.skipDeleteActions(true);

                    specTrans.skipDatabaseLog(true);

                    specTrans.skipEvents(true);

                    specTrans.skipDataMethods(true);


                    delete_from specTrans exists join custTransOpen

                       where CustTransOpen.DataAreaId == specTrans.RefCompany

                        && CustTransOpen.RecId == specTrans.RefRecId

                        && CustTransOpen.TableId == specTrans.RefTableId;


                    while select specTrans join vendTransOpen

                        where vendTransOpen.DataAreaId == specTrans.RefCompany

                        && vendTransOpen.RecId == specTrans.RefRecId

                        && vendTransOpen.TableId == specTrans.RefTableId

                        join VendTrans

                        where VendTrans.RecId == vendTransOpen.RefRecId

                        && VendTrans.AccountNum == vendTransOpen.AccountNum

                    {

                        if (!conFind(conVendInvoice, vendTrans.Invoice))

                        {

                            conVendInvoice += vendTrans.Invoice;

                            

                        }

                        totalVendInvoices++;

                    }


                    specTrans.skipDeleteActions(true);

                    specTrans.skipDatabaseLog(true);

                    specTrans.skipEvents(true);

                    specTrans.skipDataMethods(true);


                    delete_from specTrans exists join vendTransOpen

                        where vendTransOpen.DataAreaId == specTrans.RefCompany

                        && vendTransOpen.RecId == specTrans.RefRecId

                        && vendTransOpen.TableId == specTrans.RefTableId;


                    info(con2Str(conVendInvoice));

                    info(strFmt('@JP:TotalSpecTransDeletedForVendor', totalVendInvoices));

                    info("@JP:OperationCompleted");

                    ttscommit;

                }

            }

            else

                info("@JP:OperationCancelled");

}

Wednesday, July 15, 2020

Script to mark a years worth of bank transactions as cleared for bank reconciliation in Dynamics 365 finance and operations

This post I would  like to share my experience with people who is looking for reconcile years of bank transactions at single click, Of-course we can do it manually but it would be lot of time consuming for the users to select each and every transaction in case if you need to reconcile thousands of transactions.

The business need for our client is , they where using AMC banking ISV solution for all banking related activities hence they have not reconciled single transaction from couple of years. but now they would like to give up on AMC banking and go with standard module cash and bank management. 


In the process to use features like advance bank reconciliation in dynamics 365 finance and operation, either of two options should be satisfied.

1. All the fiscal periods should be open for un-reconcile transactions.
2. Or all the transactions should be reconciled. 

Option 1 would be impossible because we can't go and open all closed periods, hence we have too rely on option 2 and here I came up with script where with just one click it will reconcile all un-reconcile transaction over period. 

Below is the class which helps to solve the purpose.

public static class JP_SupportScripts
{
    public static void autoReconcilation(TransDate _accountStatementDate, BankAccountStatementNum _accountStatementNum, CompanyBankAccountId _accountId)
    {
        BankAccountStatement bankAccountStatement;
        BankAccountTrans     bankAccountTrans, bankAccountTransUpdate;
        BankAccountTable     bankAccountTable;
        int                  noOfRec;

        ttsbegin;

        select firstonly bankAccountTable
            exists join bankAccountTrans
            where bankAccountTrans.AccountId == bankAccountTable.AccountID
            && bankAccountTable.AccountID == _accountId
            && bankAccountTrans.Reconciled == NoYes::No
            && bankAccountTrans.AccountStatementDate == Global::dateNull()
            && bankAccountTrans.AccountStatement == "";

        if (bankAccountTable.RecId)
        {
            if(Box::yesNo(strFmt("Do you want to reconcile all the transaction for the bank %1", bankAccountTable.AccountID), DialogButton::Yes) == DialogButton::Yes)
            {
                bankAccountStatement.AccountId            = _accountId;
                bankAccountStatement.AccountStatementDate = _accountStatementDate;
                bankAccountStatement.AccountStatementNum  = _accountStatementNum;
                bankAccountStatement.CurrencyCode         = bankAccountTable.CurrencyCode;
                bankAccountStatement.EndingBalance        = bankAccountTable.balanceCur();
                bankAccountStatement.insert();

                while select forupdate bankAccountTransUpdate
                    where bankAccountTransUpdate.Reconciled == NoYes::No
                    && bankAccountTransUpdate.AccountId == bankAccountTable.AccountId
                    && bankAccountTransUpdate.AccountStatementDate == Global::dateNull()
                    && bankAccountTransUpdate.AccountStatement == ""
                {
                    bankAccountTransUpdate.Included = NoYes::Yes;
                    bankAccountTransUpdate.AccountStatement = bankAccountStatement.AccountStatementNum;
                    bankAccountTransUpdate.AccountStatementDate = bankAccountStatement.AccountStatementDate;
                    bankAccountTransUpdate.update();
                    noOfRec++;
                }
                info (strFmt("Bank statemant '%1' created with %2 transactions", _accountStatementNum, noOfRec));
            }
           
        }
        else
            info(strFmt('No transactions to reconcile for bank %1', _accountId));

        ttscommit;

    }

}

This script will create account statement with ending balance for the provided bank account and reconciles all the transactions.

Hope this helps , I will come-up with another interesting blog post soon, till then happy daxing :)