Set up an Object Event Script

Use this activity to set up object events scripts. All MineMarket objects can be customised to have their ObjectPropertyChange, ObjectBeforeSave and/or ObjectBeforeDelete object type events perform extra functionality.

Example: Object event script for quota names

The following script generates a name for each quota for each contract product, using the format yyyy-MM, where:

  • yyyy = 4-digit year (based on quota start date)
  • MM = 2-digit month (based on quota start date)

For example, 2015-01 is the name of the first quota generated in the year 2015.

Copy
using System;
using Mincom.MineMarket.DAL;
using Mincom.MineMarket;
/// <summary>
/// Exposes events for Quota Events business objects
/// Version 1.0
/// Description: Sets the name of quota based on the start date on save
///
///* Modification date   : 16/07/2015
///* Modified By         : Datamine
///* Changes             : 
///     Support cases addressed : None
///
///*
/// </summary>
/// 
public class QuotaEvents : IObjectEvents
{
    public QuotaEvents() { }
    /// <summary>
    /// Called on any changes to a property.
    /// </summary>
    public void ObjectPropertyChange(IEventsObject obj, ObjectPropertyChangeEventArgs e)
    {
    }
    /// <summary>
    /// Called before saving any changes to objects, including newly created objects.
    /// </summary>
    public void ObjectBeforeSave(IEventsObject obj, ObjectBeforeSaveEventArgs e)
    {
        Quota objQ = (Quota)obj;
        if (!objQ.NameGenerated)
        {
            objQ.Name = objQ.StartDate.ToString("yyyy-MM");
            objQ.NameGenerated = true;
        }
    }
    /// <summary>
    /// Called before saving deletes.
    /// </summary>
    public void ObjectBeforeDelete(IEventsObject obj, ObjectBeforeDeleteEventArgs e)
    {
    }
}

Security Note: You need the Allow script maintenance and Allow the user to maintain object events user group security rights in the Scripting user group security rights group for this activity.

Activity Steps

  1. Open the Object Events screen.
  2. If the script to be edited is already in use, click Show Only Used Scripts.
  3. Locate and select the item to be changed.
  4. Check Use Script.
  5. Click Edit Script next to the selected object.

    The Object Events (script editor) displays the script stub for the selected object and the Scripting Ribbon Tab displays.

  6. Edit the C# script.
  7. Append the public class code after any other public classes in the object event code.
  8. Ensure that script references are selected:
    1. Note the DLLs that are referenced in the script. The DLLs are listed at the top of the script, after the word "using".
    2. Select the References tab.
    3. Select the required DLLs.
  9. Click the Build icon on the Scripting ribbon tab to compile the script.
  10. Click the Save icon on the Scripting ribbon tab.