You will then be shown how to package your applications and changes, so they can be installed elsewhere and ways to maintain them easily. If you wish to create an alternative simple interface, then explore ways to make ServiceNow beautiful using Service Portal.
By the end of the book, you will know the fundamentals of the ServiceNow platform, helping you be a better ServiceNow System Administrator or developer. Explore how to implement business logic and automated workflows and write effective code by flexible choices for client-side scripting. Library of Book Mastering ServiceNow Scripting. Download e-Book. Posted on. Page Count. Andrew Kindred,. The concepts of ServiceNow are relevant for every version, but it is strongly recommended that you follow along with a Helsinki instance.
Mastering ServiceNow. Skip to content. Star Branches Tags. Could not load branches. Could not load tags. It's a great place to capture our work and keep everything we do logically separate. Depending on what configuration you do with it, there may be licensing implications to deploying it in production. But this application will stay safely on our sandbox developer system. Applications are discussed in more detail in the next chapter, and in Chapter 10 , Packaging with Applications, Update sets, and Upgrades.
Throughout this book there will be examples to show off features of ServiceNow. To make them as easy to follow as possible, it's best to use the same application scope as me. To make this possible, you should import the very starting point of my Hotel application. At the moment, it's an empty shell.
The easiest way to find a particular link is to type it in the Application Filter field at the top-left corner of the menu. Make sure you are choosing the right one, though, because some modules are identically named. Click the Browse button, and choose the XML file you downloaded. Click Upload. Once analyzed, click on Commit Update Set.
Click Close once done. Now, let's create our first table. Fill in the following values, and click on Create , then OK to confirm. Some fields like Name will automatically populate. Notice the auto-generated table name. It's made up of several parts: the vendor prefix, the application name, and the table name itself. More about this in Chapter 2 , Developing Custom Applications. Many technical items in ServiceNow have a label and name that are used in the database and in scripts.
Let's inspect the table that was just created. Helsinki comes with over 2, different data tables, and all of them can be seen here. But we are only after one of them. Find Check-in sort by Updated or filter the list to see what has been made. When you create a new table, you get some system fields. You may need to scroll down the Table form to see them. They are all updated automatically, and it is generally good practice to leave them alone. They are useful just as they are!
The autogenerated fields are very helpful to the system administrator for finding records quickly. I always add the Updated on field to my lists, since it makes finding the records I've been working on such as scripts much faster. In addition to these automatic fields, we need to create some of our own.
We will need several, but right now, let's create something to store any requests that the guest may have. Perhaps they may have specifically requested a high floor. Scroll down the table form, and create a new field called Comments by double-clicking on Insert a new row Fill out the row, and save the record by clicking on the Update button.
Either use the Tab key or double-click to enter the following data:. Once you've clicked the Update button, the instance gets busy. Behind the scenes, the application server is running SQL commands against the database.
Specifically, at the time of creating the field, the following is executed:. This will place lots of information at the bottom of the page. Other diagnostic tools such as this are discussed in Chapter 8 , Securing Applications and Data. This demonstrates a key concept: whenever you perform an action in ServiceNow, it results in a string of database commands. The database is altered and the platform's internal state is updated.
These actions are generally carried out quickly, with the whole process completed in about half a second. No downtime is necessary. The dictionary is a metatable. For example, one field might be dependent upon another. A dictionary entry might also be referred to as an element descriptor , since it describes the how the field or element works.
The table is represented by an entry in the dictionary with a table value, type of Collection , and no column name. When the Comments field was added to the Check-in table, the platform also made a dictionary entry with the table and a column name. The options that are available in the dictionary depend on the type of field you are working with. Reference fields, which we will explore in a moment, have extra functionality that is controlled here, such as dynamic creation.
As we work through ServiceNow, we'll spot functionality that is enabled through the dictionary. However, much of it can be achieved in other ways, often in a better manner. Older versions of ServiceNow have a read-only tick box available in the dictionary form by default. While it's included and can be used in later versions, it is a better idea to use security rules instead. They give you much more granularity and control than a binary checkbox.
We will explore security rules in Chapter 7 , Exchanging Data. The easiest way to navigate to a dictionary entry is by right-clicking on the label of the field not the text-entry box and choosing Configure Dictionary. You can see some details about a field, such as which table it is in, by choosing the Show option from the menu that appears on right-clicking.
The ServiceNow database is a relational database. This means that one data element can relate to another. To ensure that every record or row can be referenced easily, every record has a unique identifier: a primary key. In ServiceNow, this primary key is something that isn't related to the data itself. It is a globally unique identifier or GUID.
This GUID is stored as a character string, made of hexadecimal characters the numbers plus the letters a-f. The number of unique GUID values is so large that the probability of two accidently being the same is negligible. This is an example GUID: cccbbd1bd8cd This type of identifier is sometimes known as an OID or object identifier. It has no special significance; it just uniquely identifies a data row. It can also be called a surrogate key. The characters generated are random-a mixture of several sources, including the date and time and details specific to the instance, meaning they're not sequential or predictable.
In the new instance, you should happen across the user record of Fred Luddy if the demo data has been removed, you will get a Record not found message. It is useful to examine the structure of the URL. Then, spot the GUID. With these two items, the instance knows exactly what data it needs to pull up and present to you. It is the only field that ServiceNow really cares about. It also looks after itself. You don't need to worry about it during day-to-day operations. When we get into scripting in Chapter 2 , Developing Custom Applications , you'll be seeing more of them.
Every other field is optional and non-unique to the database platform. It is possible to enforce uniqueness in other fields too, as we'll see later. This means that, in general, you can change the value of fields to whatever you like and still maintain referential integrity; no system errors will occur.
If you want to rename a user or a group, go ahead. Many other products do not use surrogate keys; data is linked together using user-provided data. If you change the name of a group, for example, this could remove all group memberships and task assignment. Not in ServiceNow, though! An important exception to this behavior is with roles. In general, it is a good idea to keep the names of roles the same. It is a good idea not to interfere with this flexibility. Instead, use the properties or attributes of the record itself to identify it.
So, rather than hardcoding the condition that a particular room in our hotel needs special treatment, create another field and use it as a flag. The VIP flag on the User table is a good example of this. There are various types of fields provided by the ServiceNow platform. We will explore some of the simpler ones before moving on to the fundamental backbone of the data structure with reference fields:. String : These fields are simple text fields. The UI displays a string field as an editable text box.
If the Max length attribute in the dictionary is more than , then a multiline field is shown. Most fields in ServiceNow are enhanced versions of the string field. The value that is stored in the database is plain text. This lets the platform convert wip in the database to present Work in Progress to the user. Any values that don't have a label are highlighted in blue in the dropdown.
Integer choice : These fields use numbers instead of text to achieve the same result as normal choice fields. They are useful for representing states, since they allow you to use greater-than or less-than conditions, but they have proven difficult to work with since the numbers don't mean much!
Use caution when dealing with the out-of-the-box integer choice fields, such as State on the Task table. If you reuse them which is a good idea , you should always align your states to the existing ones. For example, 3 should represent Closed. If you do not align them, then users will be confused when reporting.
This is discussed in detail in Chapter 4 , Client-Side Interaction. Date : There are several date fields in ServiceNow. The time is stored as UTC in the database, and the appropriate display value is calculated by the user's profile. Currency : These are string fields that combine the currency and amount. The platform uses this information to provide conversions between different currencies.
They are rendered as tick boxes. URL : These fields provide space to enter a link, which can toggled to be clickable. Email : Similar to URL, the email field lets you type an e-mail address and provides a button to launch your e-mail client through a mailto: link. It is tempting to use HTML fields in lots of places, but they do come with overhead, and browsers have different capabilities. Test carefully if you want to use capabilities such as these. In addition to text, ServiceNow can also store binary data.
This means that anything images, music, or even a multitude of PowerPoint documents can be saved in ServiceNow. Just like everything else, binary data is stored in the database. A file is always related to another record this is why they are referred to as attachments. Information on this other record is stored with the other metadata in the Attachments table.
We'll see in later chapters that there are often better ways than manually adding attachments containing booking information. Why not have the e-mail come directly into ServiceNow? Or, even better, why not have the guests perform the booking directly with ServiceNow? One of the simplest ways to control the platform is to set properties. There are lots of things you can change by just clicking on a box or changing a value. To see how many options you can choose, type Properties in the filter-text box of the application navigator.
This collection contains some very useful options, including how forms look and feel, whether list editing is enabled, and whether Insert and Stay is always available. You may want to spend some time and find out what they do.
This will give you a large list-over in Helsinki. When designing the data structure for a hotel, you want to know which room a guest has checked in to. It won't be good for business if we don't know who is sleeping where! This is exactly what a reference field does: it creates a link between two records, one pointing to another. These are the two items needed to reference a record. So when you create a reference field, you need to select which table it should point to, which is stored in the dictionary.
And the contents of the field will be a character string. Sound familiar? Reference fields are one of the most important items to understand in ServiceNow.
However, this is meaningless to a person. Therefore, the platform allows you to pick a field that will be displayed. For a person, this might be their name. Other records might have a user-friendly reference number, like TSK This is usually an incremental number-there are scripts that generate one automatically. You can choose which field to show by ticking the Display field in the Dictionary entry.
Reference fields are used throughout ServiceNow, just like a proper relational system should be. Scripting, lists, and forms all understand references fields, as we'll see while we work through the chapters.
Let's think about something that the hotel application needs-a room directory. Each room has several attributes that defines it: its room number, how many beds it has, and which floor it is on. We can represent this information as fields in a Room record, all stored in a dedicated table. We also need to store guest information. When designing a data structure, it's a good idea to reuse functionality wherever possible. ServiceNow already has a table that stores information about people: the user table.
Let's use that for now to store guest information. It is sometimes a difficult decision to should reuse an existing table. The benefits are obvious: you save time from not duplicating work, both in configuration and maintenance. But sometimes, you need the table to work slightly differently for two different scenarios.
We'll see one way to deal with this in Chapter 2 , Developing Custom Applications. Once we have these items in place, we can modify the Check-in table to record which room has been taken by which guest. Use the New button on the list. Fill out fields as follows, click on the menu button, and then click on Save don't click on Submit! I suggest using the Save button, accessible via the three-line menu icon or right clicking on the header rather than using Submit to commit records to the database.
This ensures that the updated record is shown on screen after saving rather than redirecting to the previous page, like Submit does. Now create a field to store the room number by scrolling down the Columns tab to Insert a new Row. Double-click again to enter the information. Let's see what we've created. When we created the table, ServiceNow also created a module in the Hotel application menu that will show us all the room data in the instance.
You shouldn't be surprised to see No records to display - we haven't created any yet! Using the New button, create a few example records, giving each one a different number.
Make several on the same floor. One of them could be Room on the first floor. As you do so, try using the Save and Submit buttons, and notice the difference between them.
Note that the platform does not force you to choose different numbers for each record. Unless you mark a field as unique or create a rule to check, the platform will allow you to create them.
To mark a field as unique, you can edit the dictionary entry of that field you will need to configure the dictionary form and add the Unique checkbox. By ticking that field, you are asking the database to enforce it. It does this by making that field a unique key. This has two impacts. It creates an index on that field, which is good. However, if a user attempts to save a duplicate value, they will get a message saying Unique Key violation detected by database.
This can be a little jarring for a non-technical user. Try to catch the error with a Business Rule first. Now that we have a list of rooms, we need to create the link between the Room and Check-in records.
A reference field can be referred to as a one-to-many relationship. This is because a room may be checked in to multiple times you might have one particular guest one day, and the next day, another might sleep in the same room after our fabulous cleaners have done their work , but for a single check-in, you can only select one room.
You can only sleep in one bed at a time! A classic example of a one-to-many relationship is between a mother and her children.
A child can only have one biological mother, but a mother can have many children. The following diagram shows the relationship needed between the Room and Check-in records:. Once there, create two new reference fields-one will be for the room, using the following data:.
0コメント