Page 1 of 3

Plugin error message jiwa.

PostPosted: Tue Aug 29, 2023 4:48 pm
by JuiceyBrucey
Version SR 16, 7.2.1
When trying to save the plugin, I get this error message.
Error message:
the type of namespace name 'jiwaSales' does not exist in the namespace 'JiwaFinancialsJiwa' are you missing an assembly referance?
Code: Select all
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using JiwaFinancials.Jiwa;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing;
using ServiceStack;
using ServiceStack.DataAnnotations;
using ServiceStack.Model;
using JiwaFinancials.Jiwa.JiwaServiceModel.Tables;
using ServiceStack.Auth;
using System.Linq;
using ServiceStack.OrmLite; // Db
using System.Configuration;


namespace JiwaFinancials.Jiwa.JiwaServiceModel
{
   public class RESTAPIPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaRESTAPIPlugin
   {
      public void Configure(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin, ServiceStack.ServiceStackHost  AppHost, Funq.Container Container, JiwaApplication.Manager JiwaApplicationManager)
      {         
         //System.Diagnostics.Debugger.Launch();
         //System.Diagnostics.Debugger.Break();
         AppHost.RegisterService<CustomServices>();
         //using InvoiceID from QO_Main table as id in ToDo (TD_Main) table
         AppHost.Routes.Add(typeof(InsertToDoRequest), "/Custom/InsertToDoRequest/{InvoiceID}/{MsgSubject}/{MsgBody}/{AssignTo}/", "GET", "Inserts a ToDo note associated with a quote to create an alert.", "");
      }
   }
   #region "Requests"
      [ApiResponse(200, "Records retrieved OK")]
      [ApiResponse(401, "Not authenticated")]
      [ApiResponse(404, "Handler for Request not found")]
      public static class InsertToDoRequest
      {
         public static string InvoiceID { get; set; }
         public static string MsgSubject { get; set; }
         public static string MsgBody { get; set; }
         public static string AssignTo { get; set; }
      }          
   #endregion
      
   #region "BusinessLogicPlugin"
   public class BusinessLogicPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogicPlugin
   {

       public override object InitializeLifetimeService()
       {
           // returning null here will prevent the lease manager
           // from deleting the Object.
           return null;
       }

       public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
       {
         if (JiwaBusinessLogic is JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote)
         {         
            JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote quote = (JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote)JiwaBusinessLogic;
            quote.SaveEnd += Quote_SaveEnd;
         }
       }
      
      private void Quote_SaveEnd(object sender, System.EventArgs e)
      {
         JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote quote = (JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote)sender;
         
         if (quote.InsertFlag)
         {
            // insert flag indicates it was created.
            JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo toDo = quote.Manager.BusinessLogicFactory.CreateBusinessLogic&lt;JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo&gt;(null);
               toDo.CreateNew();
               toDo.AssignedTo.ReadRecordByUsername("Admin");
               toDo.Subject = "New Quote Created";

               toDo.Body = String.Format("Quote {0} was created.", quote.QuoteNo);

               toDo.ReminderPredefinedSetting = JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo.ReminderPredefinedSettingType.WhenDue;
               toDo.ReminderSpecificDateTime = DateTime.Now;
               toDo.ReminderEnabled = true;
               toDo.Save();
         }
      }
   }
   #endregion
   #region "Services"   
      public class CustomServices : Service
      {
         [Authenticate]
         public static void InsertToDoRequest()
           {
               Manager manager = new Manager();
            
                JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo toDo = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo>(null);
                toDo.CreateNew();
                toDo.AssignedTo.ReadRecordByUsername(request.AssignTo);
                toDo.Subject = request.MsgSubject;
                toDo.Body = request.MsgBody;
                toDo.ReminderPredefinedSetting = JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo.ReminderPredefinedSettingType.WhenDue;
                toDo.ReminderSpecificDateTime = DateTime.Now;
                toDo.ReminderEnabled = true;
                toDo.Save();
              
           }
      }
 
   #endregion
}

Re: Plugin error message jiwa.

PostPosted: Tue Aug 29, 2023 5:37 pm
by Mike.Sheen
JuiceyBrucey wrote:Version SR 16, 7.2.1
When trying to save the plugin, I get this error message.
Error message:
the type of namespace name 'jiwaSales' does not exist in the namespace 'JiwaFinancialsJiwa' are you missing an assembly referance?


The error message describes the problem - the plugin doesn't have a reference to the JiwaSales.dll

You can either add it by explicitly adding the JiwaSales.dll to the Assembly References tab, or it will be added for you if you add either the sales order entry form to the Forms tab, or the sales order business logic to the Business Logic tab.

If your plugin wants to modify business logic behaviour then you probably want to add the sales order business logic to the Business Logic tab.

If your plugin wants to modify the form behaviour, then you probably want to add the sales order entry form to the Forms tab.

Re: Plugin error message jiwa.

PostPosted: Mon Sep 04, 2023 1:07 pm
by JuiceyBrucey
Thank you for reply.
That has cleared up that error message. As I am new to C#, some of this takes a bit of back ground learning.

So the code now looks like this:
Code: Select all
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using JiwaFinancials.Jiwa;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing;
using ServiceStack;
using ServiceStack.DataAnnotations;
using ServiceStack.Model;
using JiwaFinancials.Jiwa.JiwaServiceModel.Tables;
using ServiceStack.Auth;
using System.Linq;
using ServiceStack.OrmLite; // Db
using System.Configuration;

namespace JiwaFinancials.Jiwa.JiwaServiceModel
{
   public class RESTAPIPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaRESTAPIPlugin
   {
      public void Configure(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin, ServiceStack.ServiceStackHost  AppHost, Funq.Container Container, JiwaApplication.Manager JiwaApplicationManager)
      {         
         //System.Diagnostics.Debugger.Launch();
         //System.Diagnostics.Debugger.Break();
         AppHost.RegisterService<CustomServices>();
         //using InvoiceID from QO_Main table as id in ToDo (TD_Main) table
         AppHost.Routes.Add(typeof(InsertToDoRequest), "/Custom/InsertToDoRequest/{InvoiceID}/{MsgSubject}/{MsgBody}/{AssignTo}/", "GET", "Inserts a ToDo note associated with a quote to create an alert.", "");
      }
   }
   #region "Requests"
      [ApiResponse(200, "Records retrieved OK")]
      [ApiResponse(401, "Not authenticated")]
      [ApiResponse(404, "Handler for Request not found")]
      public static class InsertToDoRequest
      {
         public static string InvoiceID { get; set; }
         public static string MsgSubject { get; set; }
         public static string MsgBody { get; set; }
         public static string AssignTo { get; set; }
      }          
   #endregion
      
   #region "BusinessLogicPlugin"
   public class BusinessLogicPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogicPlugin
   {

       public override object InitializeLifetimeService()
       {
           // returning null here will prevent the lease manager
           // from deleting the Object.
           return null;
       }

       public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
       {
         if (JiwaBusinessLogic is JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote)
         {         
            JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote quote = (JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote)JiwaBusinessLogic;
            quote.SaveEnd += Quote_SaveEnd;
         }
       }
      
      private void Quote_SaveEnd(object sender, System.EventArgs e)
      {
         JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote quote = (JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote)sender;
         
         if (quote.InsertFlag)
         {
            // insert flag indicates it was created.
            JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo toDo = quote.Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo>(null);
               toDo.CreateNew();
               toDo.AssignedTo.ReadRecordByUsername("Admin");
               toDo.Subject = "New Quote Created";

               toDo.Body = String.Format("Quote {0} was created.", quote.QuoteNo);

               toDo.ReminderPredefinedSetting = JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo.ReminderPredefinedSettingType.WhenDue;
               toDo.ReminderSpecificDateTime = DateTime.Now;
               toDo.ReminderEnabled = true;
               toDo.Save();
         }
      }
   }
   #endregion
   #region "Services"   
      public class CustomServices : Service
      {
         [Authenticate]
         public static void InsertToDoRequest()
           {
               JiwaFinancials.Jiwa.JiwaApplication.Manager manager = new JiwaFinancials.Jiwa.JiwaApplication.Manager();
            
                JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo toDo = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo>(null);
                toDo.CreateNew();
                toDo.AssignedTo.ReadRecordByUsername(request.AssignTo);
                toDo.Subject = request.MsgSubject;
                toDo.Body = request.MsgBody;
                toDo.ReminderPredefinedSetting = JiwaFinancials.Jiwa.JiwaApplication.JiwaToDos.ToDo.ReminderPredefinedSettingType.WhenDue;
                toDo.ReminderSpecificDateTime = DateTime.Now;
                toDo.ReminderEnabled = true;
                toDo.Save();
              
           }
      }
 
   #endregion
}

And now I am getting this error:
"the name 'request' does not exist in the current context"

Re: Plugin error message jiwa.

PostPosted: Tue Sep 05, 2023 10:58 am
by Mike.Sheen
JuiceyBrucey wrote:And now I am getting this error:
"the name 'request' does not exist in the current context"


Sounds like you're missing a namespace. Either fully qualify the reference to the request type or add a using statement.

If you export the plugin to XML (utilities tab of Plugin Maintenance form) and attach the plugin here, one of us can import it and get the same error and help you fix it. Providing code snippets is difficult to debug / diagnose.

Re: Plugin error message jiwa.

PostPosted: Tue Sep 05, 2023 5:54 pm
by JuiceyBrucey
That would be greatly appreciated.
Thank you very much.
Will do.

Re: Plugin error message jiwa.

PostPosted: Wed Sep 06, 2023 9:25 am
by JuiceyBrucey
Here is the exported plugin.
Thank you very much for helping with this.
Cheers

Re: Plugin error message jiwa.

PostPosted: Wed Sep 06, 2023 9:28 am
by JuiceyBrucey
P.S. I realise this is set to disabled.
<IsEnabled>false</IsEnabled>
I could not enable it due to the errors.

Re: Plugin error message jiwa.

PostPosted: Thu Sep 07, 2023 10:59 am
by Mike.Sheen
Attached is a revised version of your plugin, such that it compiles.

Your issue was that you were referring to a request and not defining it.

So,

Code: Select all
public static void InsertToDoRequest()


Changed to:

Code: Select all
public void Post(InsertToDoRequest request)


I also needed to change your static class and property types to be not static.

And I wrapped your creating of the JiwaApplication.Manager in a using statement to make sure it is disposed properly - not doing that will result in connection pool exhaustion.

If you look in the REST API plugin, there are heaps of good examples of how to perform POST, PATCH, GET and DELETE operations - you can use those as a boilerplate guide.

Re: Plugin error message jiwa.

PostPosted: Thu Sep 07, 2023 11:55 am
by Mike.Sheen
After looking further, there are some other fixes needed before this has a hope of working.

I didn't notice at first, but you were creating a new JiwaApplication.Manager instance - you shouldn't do that and that will not work - you need to retrieve it from the request and to do that you need the extension method GetManager() which is defined in the REST API plugin, so you need to add a Plugin reference to that.

Revised plugin attached.

Re: Plugin error message jiwa.

PostPosted: Fri Sep 08, 2023 2:35 pm
by JuiceyBrucey
thank you very much for the reply.
I am still getting an error unfortunately.
Please see attached image.
Thank you.
Cheers