Page 1 of 1

Knowing when a GRN is activated

PostPosted: Mon Sep 13, 2021 10:35 am
by DannyC
Hi,
In the absence of a GRN Activating or Activated event, I am doing the following to fire off some code when a GRN is activated.
It works fine, but it intermittently also fires when a GRN is only opened or read. I want it to only do it's stuff when a GRN is activated only.

I am wondering if the following code is the best way to do it or if there's a better way.
Code: Select all
bool isActivating = false;

public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{

   if (JiwaForm is JiwaFinancials.Jiwa.JiwaInvReceivalUI.MainForm)
   {
      JiwaFinancials.Jiwa.JiwaInvReceivalUI.MainForm GRNForm = (JiwaFinancials.Jiwa.JiwaInvReceivalUI.MainForm)JiwaForm;
      GRNForm.InventoryReceival.ReadEnd += My_GRNReadEnd;
      GRNForm.InventoryReceival.SaveStart += My_GRNActivated;
   }
   
}

private void My_GRNActivated(object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaInvReceival.Receival GRN = (JiwaFinancials.Jiwa.JiwaInvReceival.Receival)sender;      
   if (GRN.Status.ToString() == "Activated" && GRN.OriginalStatus.ToString() == "UnActivated")
   {
      //We're activating
      isActivating = true;
   }
   else
   {
      isActivating = false;
   }
}   


public void My_GRNReadEnd (object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaInvReceival.Receival GRN = (JiwaFinancials.Jiwa.JiwaInvReceival.Receival)sender;
    if (isActivating)
   {
      //Do stuff
   }

Re: Knowing when a GRN is activated  Topic is solved

PostPosted: Mon Sep 13, 2021 11:02 am
by Scott.Pearce
You should only be handling the Save part. Here is a sample plugin:

Plugin GRN Message Upon Activation.xml
(33.95 KiB) Downloaded 270 times