Enhancing Your Coding with Generative AI:  Guide for Dynamics 365 Consultants, Part 1
ChatGPT and Microsoft

Enhancing Your Coding with Generative AI: Guide for Dynamics 365 Consultants, Part 1

As Dynamics 365 consultants, we are continually looking for ways to streamline our workflows and deliver high-quality solutions efficiently. One promising tool is generative AI, particularly as a coding assistant. While generative AI is not yet sophisticated enough to produce flawless code independently, it serves as a valuable aide that can enhance our coding practices when used judiciously.

Generative AI coding assistants can significantly enhance the coding capabilities of Dynamics 365 consultants, even those with limited programming experience. For example, by providing intelligent code suggestions, auto-completion, and error detection, generative AI enables functional consultants to handle more complex JavaScript tasks. This reduces the reliance on specialized technical consultants. As a result, project margins can improve due to increased productivity and reduced costs.

There are two primary ways to utilize generative AI in coding. The first is through chatbots such as ChatGPT or Copilot, and the second is the more powerful GitHub Copilot, which is accessed from within an Integrated Development Environment (IDE), such as Visual Studio. We will look at chat-based generative AI in this article. While it may not offer auto-completion, chat-based AI still serves as a valuable coding assistant.

Privacy Concerns

When considering how to use these tools, it's important to first think about the privacy of your queries. For chatbots like the free version of ChatGPT, you should assume that queries and responses are public and can be used to train large language models (LLMs). This means there is no expectation of privacy. In contrast, ChatGPT Enterprise or Microsoft Copilot do not use your private data to train LLMs. This article and the next will focus on Microsoft Copilot, which is protected with your Microsoft account using "Commercial Data Protection" with TLS/AES encryption. For those using Copilot Enterprise, more extensive Enterprise Data Protection is provided through Microsoft Entra, offering DLP and control through other tools.

Using Generative AI as a Coding Assistant

Generative AI works as an assistant, not a replacement for your expertise. It can suggest code snippets and improvements, but it is crucial to apply your domain knowledge to verify and refine these suggestions. Importantly, professional standards and agreements often prohibit direct copying and pasting from public sources, necessitating a thorough review and adaptation process.

Efficiency Gains

While not focused on programming tasks, an experimental study found that consultants using generative AI were significantly more productive, finishing tasks 25% more quickly, and with over 40% higher quality compared to a control group. (Dell’Acqua et al., 2023)

Despite the need for validation when used in programming, leveraging Generative AI can reduce the overall time required for programming tasks. In my experience the reduction in effort can be 20% to 40%. This efficiency gain depends on how quickly you can identify and rectify any inadequacies in the generated code.

Practical Examples of AI-Enhanced Code

I typically use Generative AI to improve code I’ve written. Following are two JavaScript examples.

1. Control Validation:

Initial code to validate a control parameter passed to a function:

if (control)        

AI-suggested improvement:

if (control && typeofcontrol.setVisible === 'function' && typeofcontrol.getAttribute === 'function')        

This enhancement ensures more robust validation, confirming that the control object has the necessary methods before proceeding.

2. Lookup Column Validation:

Initial code to validate a lookup column value:

// Get the lookup column value.
const columnValue = column.getValue();
// Verify the column lookup object exists.
if (columnValue)        

AI-suggested improvement:

?// Get the lookup column value. 
const columnValue = column.getValue(); 
// Verify the column lookup object exists. 
if (columnValue && Array.isArray(columnValue) && columnValue.length > 0)        

This addition ensures that the column value is a non-empty array, thereby increasing the robustness of the code.

Practical Example of AI-Written Code

Generative AI can also take a specification and generate code. For example, my prompt:

Write a JavaScript function that returns the row id, name and type as an object for a Dataverse lookup column passed in as a parameter.

AI-generated result:

// Function to get the row id, name, and type from a Dataverse column
function getDataverseColumnInfo(column) {
    try {
        // Verify the column exists and has the getValue method
        if (!column || typeof column.getValue !== 'function') {
            console.warn("Invalid column provided.");
            return { rowId: null, rowName: null, rowType: null };
        }
	
        // Get the column value
        const columnValue = column.getValue();
	
        // Verify the column lookup object exists
        if (columnValue && Array.isArray(columnValue) && columnValue.length > 0) {
            const lookupObject = columnValue[0];
            const rowId = lookupObject.id.replace("{", "").replace("}", "").toLowerCase();
            const rowName = lookupObject.name;
            const rowType = lookupObject.entityType;
            return { rowId: rowId, rowName: rowName, rowType: rowType };
        } else {
            console.warn("Column lookup value is not valid.");
            return { rowId: null, rowName: null, rowType: null };
        }
    } catch (err) {
        console.error("Error in getDataverseColumnInfo:", err);
        return { rowId: null, rowName: null, rowType: null };
    }
}
	
// Example usage
// Assuming 'someColumn' is a valid Dataverse column object
const columnInfo = getDataverseColumnInfo(someColumn);
console.log(columnInfo);        

Pretty good! Try-catch block, use "const" instead of "var", strict operators, returning an object, comments for clarity, and example usage.

Applying AI to .NET Plug-ins

The principles of using AI to enhance code apply equally to .NET plug-ins, which we will look at a bit more in the next article on GitHub Copilot. The same advice also applies to any Generative AI code. It can offer valuable suggestions, but you must review these carefully to ensure they meet your specific requirements. Never trust generated code; instead, use your expertise to validate and refine it.

Maximizing Value for Clients

By integrating generative AI into your coding practice, you can produce more robust and reliable solutions. This not only enhances your efficiency but also provides better value to your clients. The improvements suggested by AI can make a significant difference in the quality and maintainability of your code.

Next Up

The next article will continue this exploration of strategies for effectively harnessing the power of large language model generative AI in Dynamics 365 consulting by exploring GitHub Copilot.

Enhancing Your Coding with Generative AI: Guide for Dynamics 365 Consultants, Part 2

Works Cited

First article in this series: Understanding AI's Influence on Dynamics 365 Consulting

Dell’Acqua, F., McFowland III, E., Mollick, E. R., Lifshitz-Assaf, H., Kellogg, K., Rajendran, S., Krayer, L., Candelon, F., & Lakhani, K. R. (2023). Navigating the Jagged Technological Frontier: Field Experimental Evidence of the Effects of AI on Knowledge Worker Productivity and Quality. Harvard Business School Technology & Operations Management Unit Working Paper, No. 24-013. Available at SSRN: https://ssrn.com/abstract=4573321

Additional Comment (July 5, 2024)

There are two interesting new tools:

ChatGPT "Code Preview Extension: This browser extension lets you preview and interact with code snippets directly within the ChatGPT interface. Learn more on GitHub at https://github.com/ykyritsis/ChatGPT-code-preview. (Requires some developer knowledge.)

Features

  1. Live Code Preview: Instantly see the output of HTML, CSS, and JavaScript code.
  2. Syntax Highlighting: View code with proper syntax highlighting for better readability.
  3. Copy Code: Easily copy the entire code snippet to your clipboard.
  4. Download Code: Download the code snippet as a file with the appropriate extension.
  5. Resizable Preview: Adjust the size of the preview panel to your liking.

GitHub

Claude 3.5 Sonnet Artifacts: Watch Claude create content like code snippets and website designs in real-time. Try it out at https://claude.ai.

Claude 3.5 Sonnet



Stanley Russel

??? Engineer & Manufacturer ?? | Internet Bonding routers to Video Servers | Network equipment production | ISP Independent IP address provider | Customized Packet level Encryption & Security ?? | On-premises Cloud ?

4 个月

Leveraging generative AI as a coding assistant presents exciting opportunities for Dynamics 365 consultants to streamline workflows and deliver high-quality solutions efficiently. While not without its challenges, this technology empowers consultants with intelligent code suggestions, auto-completion, and error detection, enabling them to tackle complex JavaScript tasks with greater confidence and independence. By embracing chat-based generative AI tools and addressing privacy concerns, consultants can enhance their coding practices, improve project margins, and drive innovation in Dynamics 365 consulting. How do you foresee the integration of generative AI shaping the future of coding practices within the Dynamics 365 ecosystem, and what potential benefits do you anticipate for consultants and clients alike?

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了