In the last episode, we talked about working with the most important part of the Global Context - Metadata Object managers. Now let’s get through the rest of it. But first, let me swap these guys for now just like this. So. Next up are the System Objects.
They live in the Global Context properties mixed with all the Metadata Object managers from the last episode. Let’s take this ClientApplication object for example. And these are its methods we can use to control some end-user application properties. We can check out and set the font size, the caption, etc. You might remember how we used this object back in the day to change the main window caption in one of the Module 2 episodes. Here we’re calling this object, asking it to run the SetCaption method, and passing this function’s return value as a parameter.
And this is where the function lives. It reads and returns the CompanyName constant value, and boom! Whatever we save to this constant ends up being our application caption.
Next up: the general-purpose methods, numerous and versatile. They are grouped into these folders according to their purposes. There is no way on Earth we could get through all of them in a reasonable time for, boy, they are plentiful. So I suggest you browse through them on your own.
But there is one example of us using some of these methods recently. Let’s open this date-type functions folder and here are the BegOfTheMonth and the EndOfTheMonth functions. And this is how we used this function in the source code. When we post the Sales document, we check the monthly turnover on the current Loyalty Card, using this piece of code right here. This is the document’s actual date, and these are our general-purpose friends from the Global Context. Debugging this code we can see the date of the document, which is October the 4th. BegOfMonth returns October the 1st and EndOfMonth returns October the 31st, so we pass the entire month to this Turnovers method of the register.
And to the last part of the Global Context: the system enumerations and value sets. The system enumerations live here, and they are nothing but value types with fixed lists of possible values. For example, this AccumulationRecordType is a value type allowing either Expense or Receipt value. This type is used for the accumulation register’s RecordType standard attribute. Remember this one? Let me show you.
I’m opening the Inventory accumulation register and here is our RecordType standard attribute. And this is how we assign the AccumulationRecordType enumeration value to the RecordType attribute when posting a Sales document. We create a new register record, and tell the Platform that this record should subtract from the balance.
As for the value sets, they sit in this folder and, unlike the system enumerations, are not types but rather collections of various values the Platform keeps for our convenience. For example, we can use this Chars value set to add invisible symbols like Tab or Line Feed to a string, but it doesn’t prevent us from using any other symbols, including other invisibles that are not in this value set.
And this is how we used this value set in our source code. If there are not enough products for a Sales document we are posting, we prepare a message for a user, using the Line Feed invisible symbol to split the message into several lines like this. And this is how it looks like when we try to sell more than we have. This is our message split by these invisible Line Feed symbols from the Chars value set.
So, this was the Global Context and how we can use it in the source code. Of course, we didn’t cover each and every Global Context feature. Not even close. But this should be enough for you to start digging in and discovering other parts of the Global Context when you need them.