Search code examples
c#dynamics-gpeconnect

Microsoft Dynamic GP extension assembly


I have created a Dynamic GP extension method to spec following the MSDN guidelines Dynamics GP Extension Assembly

Here is the code for my custom extension assembly:

namespace MyGPService
{
  public static class GPExtensions
  {
    public static void OnRecordCreated(object sender, BusinessObjectEventArgs e)
    {
      try
      {      
        Customer customer;
        Extension CustomerEmailExtension = new Extension();
        //get current cust connection
        //connection = Connection.GetInstance();
        if (e.BusinessObject.GetType() == typeof(Customer))
        {
          customer = (Customer)e.BusinessObject;
          // Look at the Extension list passed along
          foreach (Extension ext in customer.Extensions)
          {
            Logger.LogExtention(ext);
          }
        }
        else
        {
          Logger.LogExtentionType(e.GetType().ToString());
        }
      }
      catch (Exception ex)
      {
        Logger.LogException(ex.Message);
      }
    }
  }
}

This code includes some logging mechanisms that log any incoming data to the local drive (to give me a further understanding of whats passing through during testing).

Below is my BusinessObjectsFile.config file entry (Further explained Business object configuration file

<DictionaryEntry>
 <Key xsi:type="xsd:string">Microsoft.Dynamics.GP.Customer</Key>
    <Value xsi:type="BusinessObjectConfiguration">
            <Event>
                <EventName>Created</EventName>
                <EventHandlerType>
                    <Type>Microsoft.Dynamics.Common.BusinessObjectEventHandler</Type>
                    <Assembly>Microsoft.Dynamics.Common</Assembly>
                </EventHandlerType>
                    EventHandler>
                        <SoftwareVendor>XYZ</SoftwareVendor>
                        <Type>MyGPService.GPExtentions</Type>
                        <StaticMethod>OnRecordCreated</StaticMethod>
                        <Assembly>MyGPExtensionMethods</Assembly>
                        <Execute>true</Execute>
                    </EventHandler>
            </Event>
    </Value>
</DictionaryEntry>

After i have configured the appropriate changes (Placed the new extension assembly in C:\Program Files\Microsoft Dynamics\GPWebServices, configured the BusinessObjectFile.config, then restarted Microsoft Dynamics GP Service Host. I then create a new customer, created a PO and SO for that customer and nothing is getting logged???

Logging method:

public static void LogException(string error)
{
  try
  {
    string path = Path.Combine(Utilities.SystemDirectory, "GPExtentionMethod\\Errors\\ExtErrorLog.txt");
    if(!Directory.Exists(Path.GetDirectoryName(path)))
      Directory.CreateDirectory(Path.GetDirectoryName(path));
    if (!File.Exists(path))
    {
      // Create a file to write to. 
      using (StreamWriter sw = File.CreateText(path))
      {
        sw.WriteLine("GP Extention Error Log");
        sw.WriteLine("");
      }
    }
    using (StreamWriter sw = File.AppendText(path))
    {
      sw.WriteLine(Environment.NewLine);
      sw.WriteLine("Error");
      sw.WriteLine(DateTime.Now.ToString() + ": " + error);
    }
  }
  catch { }
}

I have followed everything up to deployment and i cannot figure out why this extension method never gets called from GP? Am i missing (or should i say Microsoft) part of this puzzle?


Solution

  • I was under the assumption this method would fire after altering data directly through the Dynamics GP application, i was wrong. The only way this method would have been hit would have been through using the methods in the GP Web Services SDK, apparently Microsoft didn't think the back-end of the Dynamics GP software should have this great functionality...

    Since this did not fit our requirements i ended up using eConnect's incoming and outgoing services that work together with MSMQ. I can now add the tables i need to monitor via eConnect's Requester Setup Tool. Lastly, i have created a small client service that monitors my custom MSMQ path and instantly obtains the transaction from GP as it happens.

    GP development on the web is limited to none (if i did find anything it was irrelevant due to a different version of GP) ... It came down to lots of reading off MSDN to put this together... The GP forums were also no help for this particular case.