TUESDAY, FEBRUARY 07, 2012

Posts Tagged ‘Business rules’

I
doubt if there’s a single concept in Service-now that is more valuable to understand than how to use GlideRecord methods to query, insert, update, and delete records in your system. These methods have a wide variety of uses and are found at the heart of many of the business rules, UI actions, and scheduled job scripts that are essential to tie together your organization’s processes in your Service-now instance.

While the content of this post isn’t new information (additional examples can be found on the Service-now wiki), my aim is to provide a single page of information containing some common examples of these methods as a reference. This is an excellent page to keep bookmarked!

Learn more ...

A

n important part of managing the flow of any record submission is to be able to validate the information from the form or record and provide feedback to the end-user if there is something that they need to change. While there are many ways to validate different kinds of data, preventing the submission of that data is pretty straight-forward. In Service-now, there are two different ways to stop the submission of a record. One method works client-side (in the rendered html form) and the other method works in server-side javascript as the record hits the database.

Learn more ...

H

ere’s a quick tip that shows you how to retrieve the name or URL of your Service-now instance. This can come in handy if you need to construct a URL in a business rule or mail script or if you have some automated post-clone configuration when dealing with multiple Service-now instances in your environment.

Learn more ...

H

ere are some examples of how you could use a simple Javascript ‘split’ method to parse out the date and/or time value from a date/time field.  Both examples split out the date and time, populate them into variables, and then populate the date section into a regular date field on the same record.

Business rule example:

This could also be used in a graphical workflow ‘Run script’ activity but would need to include ‘current.update()’ at the end to call the update to the record.

Name: Populate Date from Date/Time
When: Before
Update: True
Condition: current.u_start_date_time.changes()

var dateSection = current.u_start_date_time.split(' ')[0]; //Gets the Date
var timeSection = current.u_start_date_time.split(' ')[1]; //Gets the Time
//Set the value of the Date field with the date from the Date/Time field
current.u_start_date = dateSection;


Client script example:

As is the case with all client scripting in Service-now, all fields referenced must actually be part of the rendered form (though they may be invisible) to be referenced by the client-side script.

Name: Populate Date from Date/Time
Type: OnChange
Field name: Start date/time (or whatever your date/time field is named)

function onChange(control, oldValue, newValue, isLoading) {
  //If the page isn't loading
  if (!isLoading) {
    //If the new value isn't blank
    if(newValue != '') {
      var dateSection = g_form.getValue('u_start_date_time').split(' ')[0]; //Gets the Date
      var timeSection = g_form.getValue('u_start_date_time').split(' ')[1]; //Gets the Time
      //Set the value of the Date field with the date from the Date/Time field
      g_form.setValue('u_start_date', dateSection);
    }
  }
}

A

t some point somebody a lot smarter than me (probably the first person who reads this) will see the title of this article and say “No duh! JavaScript and Java are completely different. What a waste of an article!”. You can actually find quite a bit of information on this topic out on the internet but let’s face it, anybody who isn’t in IT or Development probably doesn’t care anyway.

Since both of these technologies are used in Service-now though, this confusion often presents itself so it is good to be informed.

Learn more ...

This is a great function that you can use to eliminate duplicates from an array in Service-now. It’s just standard JavaScript so it will work in Client Scripts, Business Rules, or pretty much anywhere else you want to put it. The function takes an array as the input parameter and returns an array…minus the duplicate values!

function checkDuplicates(a) {
   //Check all values in the incoming array and eliminate any duplicates
   var r = new Array(); //Create a new array to be returned with unique values
   //Iterate through all values in the array passed to this function
   o:for(var i = 0, n = a.length; i < n; i++){
      //Iterate through any values in the array to be returned
      for(var x = 0, y = r.length; x < y; x++){
         //Compare the current value in the return array with the current value in the incoming array
         if(r[x]==a[i]){
            //If they match, then the incoming array value is a duplicate and should be skipped
            continue o;
         }
      }
      //If the value hasn't already been added to the return array (not a duplicate) then add it
      r[r.length] = a[i];
   }
   //Return the reconstructed array of unique values
   return r;
}

One of the great features of Service-now.com is its CMDB and relational mapping.  You can easily set up relationships between any CIs in the system.  Once the relationships are defined, it becomes very simple to pull up a visual representation of a CI and its dependencies by using Service-now BSM maps.  Using this feature allows an end user to look at that CI and identify what else in the environment is impacted by an outage or a change to that CI.

Learn more ...

System security is probably one of the more challenging things to implement in Service-now.com.  While an out-of-box Service-now instance comes with the core security built-in, any implementation will inevitably have customizations in this area.  At some point, I plan on writing a basic security guide to help administrators and consultants make informed decisions about how security should be implemented in their systems.

I’ve now added the security guide I promised! Check out the ‘What Everybody Should Know about ServiceNow Security‘ article for more details!

One little-known, but extremely useful access control method is to use business rules to restrict record access in your system.  You can do this by creating what I call a ‘Before Query’ business rule.  These business rules have a ‘When’ value of ‘Before’ and also have the ‘Query’ checkbox selected.  ‘Before Query’ business rules are only used when you need to restrict access to certain rows within a table for certain groups of individuals.  Because the security is controlled by a script, the restriction can be applied based on roles, group membership, company or department information from the user record, or pretty much anything else that you can derive about the user trying to access a set of records.  There are a few of these business rules out-of-box that serve as great examples of how to implement security in this way.  When I need to implement security with a ‘Before Query’ business rule, I usually start with the ‘incident query’ business rule as my template.

Learn more ...

S

ervice-now.com provides a very robust and simple way to manage your tasks and approvals (among other things) through its graphical workflow engine.  It is very common to use graphical workflow to help facilitate some change management process within your organization.  One common requirement in change management is to be able to cancel or close the change request at any time during the process.  “Simple”, you say.  “Just allow the user to change the value of the ‘State’ field to ‘Closed’.”

You would not be incorrect in saying something like that, but you would be forgetting about part of the problem with closing or canceling a change request or other task ticket.  What if the attached workflow(s) still think that the change request and its associated tasks and approvals are still in progress?  Should the attached workflow context(s) continue to run indefinitely?  If your workflow doesn’t have a way to know about the completion of the change request then it will continue to run (or more likely just sit and be forgotten).

Learn more ...

W

hen implementing the Change management process in Service-now you’ll probably encounter a scenario where your entire change workflow (including all tasks and approvals) needs to be reset.  The first option to consider (assuming you’re using the graphical workflow engine to manage the tasks and approvals) is the Rollback workflow activity.  The rollback activity works great for a lot of scenarios, but what if you don’t have a defined point in the workflow where everything should be rolled back?  What if the rollback (or reset) can happen at any point in time?  There’s not really an easy way to handle this within the workflow itself since you would need to check for a rollback condition at an infinite number of places.

Learn more ...


Latest Comments

  • Mark Stanger: This linkage all happens for you if you use the task survey plugin. You can look on the wiki for more...
  • Vineeth: I want a way in which if a survey is filled in by the user the response are stored in the survey response...
  • Mark Stanger: This functionality doesn’t connect to an FTP server. See this line in the post above…...
  • Mark Stanger: The report page is back-end XML so there’s no way to directly manipulate the behavior of that...