Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Dynamics 365 for Finance and Operations Development Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
Dynamics 365 for Finance and Operations Development Cookbook

Dynamics 365 for Finance and Operations Development Cookbook

By : Abhimanyu Singh, Agarwal
2.7 (3)
close
close
Dynamics 365 for Finance and Operations Development Cookbook

Dynamics 365 for Finance and Operations Development Cookbook

2.7 (3)
By: Abhimanyu Singh, Agarwal

Overview of this book

Microsoft Dynamics 365 for Finance and Operations has a lot to offer developers. It allows them to customize and tailor their implementations to meet their organization’s needs. This Development Cookbook will help you manage your company or customer ERP information and operations efficiently. We start off by exploring the concept of data manipulation in Dynamics 365 for Operations. This will also help you build scripts to assist data migration, and show you how to organize data in forms. You will learn how to create custom lookups using Application Object Tree forms and generate them dynamically. We will also show you how you can enhance your application by using advanced form controls, and integrate your system with other external systems. We will help you script and enhance your user interface using UI elements. This book will help you look at application development from a business process perspective, and develop enhanced ERP solutions by learning and implementing the best practices and techniques.
Table of Contents (18 chapters)
close
close
Title Page
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Dedication
Preface

Renaming the primary key


Most of you who are familiar with the Dynamics 365 for Finance and Operations application, have probably used the standard Rename function. This function allows you to rename the primary key of almost any record. With this function, you can fix records that were saved or created by mistake. This function ensures data consistency, that is, all the related records are renamed as well. It can be accessed from the Record information form (shown in the following screenshot), which can be opened by selecting Record info from the right-click menu on any record:

A new form will open as follows:

Click on the Rename button to rename the Vendor Account field value.

When it comes to mass renaming, this function might be very time-consuming as you need to run it on every record. An alternative way of doing this is to create a job that automatically runs through all the required records and calls this function automatically.

This recipe will explain how the record's primary key can be renamed through the code. As an example, we will create a job that renames a vendor account.

How to do it...

Carry out the following steps in order to complete this recipe:

  1. Navigate to Accounts payable | Vendors | All vendors and find the account that has to be renamed, as shown in the following screenshot:
  1. Click on Transactions in the Action pane to check the existing transactions, as shown in the following screenshot:
  1. Create a new project, create a runnable class named VendAccountRename, and enter the following code snippet. Use the previously selected account:
        class VendAccountRename 
       {         
         /// <summary> 
         /// Runs the class with the specified arguments. 
         /// </summary> 
         /// <param name = "_args">The specified arguments.</param> 
         public static void main(Args _args) 
        {    
          VendTable vendTable; 
 
          ttsBegin; 
 
          select firstOnly vendTable 
          where vendTable.AccountNum == '1002'; 
 
          if (vendTable) 
         { 
           vendTable.AccountNum = 'US-1002'; 
           vendTable.renamePrimaryKey(); 
         } 
 
          ttsCommit;      
        } 
 
       } 
  1. Select class VendAccountRename and right-click and then select Set as startup object. Execute the class by clicking Start in Visual Studio and check whether the renaming was successful, by navigating to Accounts payable | Vendors | All vendors again and finding the new account. The new account should have retained all its transactions and other related records, as shown in the following screenshot:
  1. Click on Transactions in the Action pane in order to see whether the existing transactions are still in place, as shown in the following screenshot:

How it works...

In this recipe, we first select the desired vendor record and set its account number to the new value. Note that only the fields belonging to the table's primary key can be renamed in this way.

Then, we call the table's renamePrimaryKey() method, which does the actual renaming. The method finds all the related records for the selected vendor account and updates them with the new value. The operation might take a while, depending on the volume of data, as the system has to update multiple records located in multiple tables.

notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon

Create a Note

Modal Close icon
You need to login to use this feature.

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Edit Note

Modal Close icon
Write a note (max 255 characters)
Cancel
Update Note