none
Creating Add-in for Dynamics Nav using C# RRS feed

  • Question

  • I'm currently working on an add-in for Dynamics Nav in Visual Studio.

    The project's files consists of a .cs file, a .dll file, and a .pdb file which I've copied into the Add-ins folder for Nav.

    The C# code consists of four public, static methods. One returns a boolean value and the others return string values.

    The methods take a string or multiple strings as arguments.

    I created the project in Visual Studio as a class library project with the correct framework.

    The issue that I'm having is that whenever I attempt to add the DotNet variable to Nav, I'm able to select the assembly, but the type list (members/methods) is empty. As a result I end up with an empty sub-type field and cannot use any of the methods.

    Here is the C# code:

    namespace TokenProcessor
    {
        using System;
        using System.Text.RegularExpressions;
        using System.Windows;
        using Microsoft.Dynamics.Framework.UI.Extensibility;
        using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;
    
        class ProcessTokens
        {
            public static bool HasTokens(string text)
            {
                string emailText = text;
    
                Regex regWBrackets = new Regex(@"\[\w+\]");
    
                Match match = regWBrackets.Match(emailText);
    
                bool hasTokens = false;
                if (match.Success)
                {
                    hasTokens = true;
                }
    
                return hasTokens;
            }
            public static string GetNextToken(string text)
            {
                string emailText = "";
    
                if (text != null || text != "") { emailText = text; }
    
                Regex regWBrackets = new Regex(@"\[\w+\]");
    
                //find tokens
                Match match = regWBrackets.Match(emailText);
    
                string token = match.ToString();
    
                return token;
            }
            public static string ReplaceNextToken(string text, string replacement)
            {
                string emailText = "";
    
                if (text != null || text != "") { emailText = text; }
    
                Regex regWBrackets = new Regex(@"\[\w+\]");
    
                emailText = regWBrackets.Replace(emailText, replacement, 1);
    
                return emailText;
            }
            public static string ReplaceAllTokens(string text, string replacement, string token)
            {
                string emailText = "";
    
                if (text != null || text != "") { emailText = text; }
    
                Regex regWBrackets = new Regex(Regex.Escape(token));
    
                emailText = regWBrackets.Replace(emailText, replacement);
    
                return emailText;
            }
        }
    }


    • Edited by thisguy17 Wednesday, June 21, 2017 9:44 PM corrected string declarations...
    Wednesday, June 21, 2017 9:39 PM

Answers

  • The answer was in the following changes and (though this may not have changed much or anything, at all) I also added an xml manifest file, with no content between the <manifest> tags, to the ProcessTokens folder in the add-ins folder.

    I ended up recreating the project, so there may be other small changes (var/class/method names). The bolded sections are the main changes.

    using Microsoft.Dynamics.Framework.UI.Extensibility;
    using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;
    using System;
    using System.Linq;
    using System.Text.RegularExpressions;
    
    namespace TokenProcessor
    {
        [ControlAddInExport("Token Processor")]
        public class TokenProcessor : WinFormsControlAddInBase
        {
            [ApplicationVisible]
            public static bool HasTokens(string text)
            {
                string emailText = text;
    
                Regex regWBrackets = new Regex(@"\[\w+\]");
    
                Match match = regWBrackets.Match(emailText);
    
                bool hasTokens = false;
                if (match.Success)
                {
                    hasTokens = true;
                }
    
                return hasTokens;
            }
            [ApplicationVisible]
            public static string GetNextToken(string text)
            {
                string emailText = "";
    
                if (text != null || text != "") { emailText = text; }
    
                Regex regWBrackets = new Regex(@"\[\w+\]");
    
                //find tokens
                Match match = regWBrackets.Match(emailText);
    
                string token = match.ToString();
    
                return token;
            }
            [ApplicationVisible]
            public static string ReplaceNextToken(string text, string replacement)
            {
                string emailText = "";
    
                if (text != null || text != "") { emailText = text; }
    
                Regex regWBrackets = new Regex(@"\[\w+\]");
    
                emailText = regWBrackets.Replace(emailText, replacement, 1);
    
                return emailText;
            }
            [ApplicationVisible]
            public static string ReplaceAllTokens(string text, string replacement, string token)
            {
                string emailText = "";
    
                if (text != null || text != "") { emailText = text; }
    
                Regex regWBrackets = new Regex(Regex.Escape(token));
    
                emailText = regWBrackets.Replace(emailText, replacement);
    
                return emailText;
            }
    
            protected override System.Windows.Forms.Control CreateControl()
            {
                throw new NotImplementedException();
            }
        }
    }

    • Marked as answer by thisguy17 Thursday, June 22, 2017 4:26 PM
    Thursday, June 22, 2017 4:26 PM