Mod-Removal and the Unexpected Surprises; OIS101 – Remembering the UoM

A script to retain the quantity U/M and price U/M after each line is entered in OIS101.

Background

Some of you may have got the impression that I have an intense dislike of modifications. You’d be correct. Mods are evil. Pure unadulterated evil.

Even worse is when modifications have been modified and not been documented.

And what I dislike even more is when you make an assumption and really don’t test your deployment methodology as thoroughly as you should.

http://imgur.com/gallery/y7Hm9

🙂

It wasn’t quite that bad, but the testing wasn’t fantastic.

Ok, as I have mentioned in other posts and in a couple of presentations we have a modification which tells my staff the percentage of a 20′ container each of their order lines in OIS101 consumes and also provides a total. This percentage is an approximate amount – as those of you that have dealt with shipping containers (especially refrigerated containers) no doubt know, not all containers are equal [in volume]. That combined with different sized cartons being mixed and potentially stacked in different ways can change the percentages quite significantly.

We have made a minor change to one of our processes so we can use discounts against our Australian export orders, this meant we wanted to change the columns in OIS101 for the views that had the container percentage. Unfortunately with our last mod uplift they borked some of the code so we couldn’t save changes to the view due to the container percentage column not existing – something we didn’t pick up on until a few weeks ago and the mod got uplifted in 2010 <sigh>. Evil mod.

So, I had written a jscript which illustrated not only adding a column, populating it but it also populated the extra column from data pulled from a webservice on a different thread – all made possible by some very intelligent people giving me the framework – inparticular Thibaud and Karin. This script I had written and largely finished approximately a year ago but needed some polish and them some testing. Other priorities got in the way before I could organise it to be tested (users and testing, like hearding cats at times!). So, priorities changed, tweaked the code and tested. It looked good, so rolled it out in to PROD alongside the modification – it’s a fairly innocuous change so was pretty confident there wouldn’t be any issues. Asked the users to keep an eye on the percentages and let me know if anything was wrong.

It all worked swimmingly. So I removed the modification on the weekend.

On Wednesday I got a call “Um, when I put an order line in and change the unit of measure and then add the line, the unit of measure clears so on the next line I have to re-enter the unit of measure. It used to remember the unit of measure”.

I thought that this is a stretch – the modification shouldn’t have done this. And I did have to manually rename the modified classes and views rather than use LifeCycle Manager to remove them (that’s a tale for another day).

Looked high and low for a setting which would retain those two values, couldn’t find one and eventually caved and logged a support case. After a little confusion I was told that no, it’s not standard functionality.

Aside from being a little disappointed that I should have really gone through some proper testing in a test environment including checking that the users were happy with the complete removal of the modification, it wasn’t too much of a drama to throw a quick script together yesterday.

So, what we want is the U/M for the quantity and the price to be remembered after each line is entered. When the user enters the order they should be blank.

We enter our first line

And then hit Add or Enter

And we see this. Nothing really complicated at all. Now if our users are entering in several lines that have the same alternate UoM then they don’t have to key in the values after the first time.

The Script
Anyways, here’s the script – enjoy:

// Remember the UoM on OIS101
// Retrieve/Populate values from OBALUN
// Retrieve/Populate values from OBSPUN

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

package MForms.JScript
{
    class OIS101_RememberUoM_01
    {
		// this is the name of the controls that we will be retrieving values
		// from and also updating
        var gstrInstanceKeyOBALUN : String = "OBALUN";
        var gstrInstanceKeyOBSPUN : String = "OBSPUN";

        var gController = null;

        public function Init(element: Object, args: Object, controller : Object, debug : Object)
        {
            var content : Object = controller.RenderEngine.Content;
            var strOBALUN : String = null;
            var strOBSPUN : String = null;
            gController = controller;

            var lvListView = controller.RenderEngine.ListControl.ListView;
			// verify we have a ListView
            if((null != lvListView) && (null != lvListView.ItemsSource) && (lvListView.ItemsSource.Count >= 1))
            {
				// attempt to retrieve our UoM and then set them
                setUoMToUI(gstrInstanceKeyOBALUN);
                setUoMToUI(gstrInstanceKeyOBSPUN);
            }
			// we want to monitor the Requested event so we can
			// save new UoM and so we can remove our event handler
            controller.add_Requested(OnRequested);
        }

        public function OnRequested(sender: Object, e: RequestEventArgs)
        {
            var lvListView = gController.RenderEngine.ListControl.ListView;

            if((null != lvListView) && (null != lvListView.ItemsSource))
            {
				// get the values from the GUI and save them
                getUoMFromUI(gstrInstanceKeyOBALUN);
                getUoMFromUI(gstrInstanceKeyOBSPUN);
            }

			// check to see if we are leaving OIS101, if we are we should remove our cached values
			if( (e.CommandValue == MNEProtocol.KeyF03) || (e.CommandValue == MNEProtocol.KeyF12))
			{
				InstanceCache.Remove(gController, gstrInstanceKeyOBALUN);
				InstanceCache.Remove(gController, gstrInstanceKeyOBSPUN);
			}

			// remove the event handler, we will reattach when the panel is updated (Init() gets called)
            gController.remove_Requested(OnRequested);
        }

        // here we shall retrieve the values from the panel and save them
		// for so we can populate the fields later
        private function getUoMFromUI(astrName : String)
        {
            var strValue : String = null;
            if(false == String.IsNullOrEmpty(astrName))
            {
                var tbTextBox : TextBox = ScriptUtil.FindChild(gController.RenderEngine.Content, astrName);
                if(null != tbTextBox)
                {
                    strValue = tbTextBox.Text;
					// if we don't have a value, then we shouldn't
					// save anything to the InstanceCache
                    if(false == String.IsNullOrEmpty(strValue))
                    {
                        InstanceCache.Add(gController, astrName, strValue);
                    }
                }
            }
        }

        // we set the values that we saved earlier
        private function setUoMToUI(astrName : String)
        {
            if(false == String.IsNullOrEmpty(astrName))
            {
                if(InstanceCache.ContainsKey(gController, astrName))
                {
                    var strValue : String = InstanceCache.Get(gController, astrName);
                    if(false == String.IsNullOrEmpty(strValue))
                    {
                        var tbTextBox : TextBox = ScriptUtil.FindChild(gController.RenderEngine.Content, astrName);
                        if(null != tbTextBox)
                        {
                            tbTextBox.Text = strValue;
                        }
                    }
                }
            }
        }
    }
}

This entry was posted in Development, M3 / MoveX. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s