Stumbling through Service Portal: Embedding Video Tags in KB Articles

My journey through the Service Portal continues this week with an unexpected turn – adding video tags to the HTML of knowledge articles.  This started from a request from a manager in another group, asking if it was possible.  We found a few questions and answers on the community, but no complete answers.  Finally, we recently had a breakthrough, and in the spirit of sharing knowledge (pun intended), I thought I’d make it known.

Continue reading

Knowledge16 – Pragmatically Conquering Your Instance With Automated Testing Pt 2

Last time I discussed some of the improvement I’ve seen in development since automated tests have been a standard part of our development process.  I also promised to continue discussing what I will be speaking on in May at CreatorCon.  So let’s get to that today with a look at server side unit testing using something I’ve developed (and am continually working on to make usability improvements), UnitTestNOW.

Continue reading

How to Use UnitTestNOW

Link to Download Update Set

Version 1 – 4/21/16 (Documentation)

Writing Tests

After installing the update set, bring up the UnitTestNOW application in your left nav.  It should look like what is the picture below:

unittestnow

Click on Scheduled Unit Tests, and the the New button at the top of the page to make a new Unit Test record.

unittest_form

Give your unit test a name, and if you’d like, change how often it runs.  You can also take this opportunity to link it to a script include.

I’ve left the default script field to contain the setSetup and setTeardown functions, but if you don’t need to create anything, feel free to ignore them or delete them.  Set the nae of the table with the setTableName function, then change the test name.

Inside each test, set the name of the function you are testing with the setFunctionName function.  Now you’re officially ready to test.

An example of each assertion is in the default code.  You may want to copy them for easier use later.

Inside the body of the test function, create the logic to run your tests.  For example, let’s take the following script include: TaskStateUtil, which is an out of the box script include.  I simply picked this one at random.

Right off the bat I see that the isStateInactive function is ripe for a test.  It just takes a single parameter (state), and returns a boolean if it’s an inactive state, based on the constants of the class.

So let’s write a test for that function.  Looking at the constants, I expect that 3, 4, and 7 will be my inactive states.

first_test

I expect a pass here, but much to my surprise, I’m given a failure.

first_test_result

After adding some log statements, I find that the variable “this.inactiveStates” was “undefined”, which is why it never hits the true condition.  I replace that variable with this.SYSTEM_INACTIVE_STATES, which is class constant, and…

second_test

Horray, the test passes, just like we expect.  Let’s add a few more cases, testing -5, 0, 1, 2, 4, 5, 6, 7, and 8.

second_test_refactored

second_test_result

Great, everything is working fine so far.  Let’s see what happens if we add them as strings.  I expect them to work just fine.

third_run

third_result

Once again, everything passes.  Fantastic.  Let’s add cases for an empty input, an empty string input, null, and undefined, just to make sure we get “true” (since none of those are 3, 4, or 7).

fourth_run

fourth_result

Is this satisfying enough for one method?  We have 22 tests for it.  If this behavior is desired, and we feel we have enough scenarios, let’s move on.  If something is bothering you about this, keep at it.

We could make this test production safe in a couple of ways.  One, we could change the initialize method to not completely crash if it doesn’t receive a GlideRecord.  (Try creating the TaskStateUtil object without a GlideRecord, and see what happens!).  That way we don’t need a record at all to any tests.  We could also get a record we know will be there, but that’s a lot less reliable and is prone to errors caused by a record being deleted or cloned over.

Knowledge16 – Pragmatically Conquering Your Instance With Automated Testing

As some of you may know, I’m speaking at CreatorCon this year about the subject of automated testing in ServiceNow.  If you plan on attending my session, I’m going to speak on server side unit tests (using SNUnit/UnitTestNOW, which I’ve recently made a little better), client side unit tests (using QUnit), functional acceptance testing (using Selenium Web Driver), and web services testing using REST Assured.  Since we’re roughly four weeks away, I’ll spend some of that time previewing what I’m discussing.

Continue reading

An Exercise in Sensibility – Approvals with Attachments From The Approving Record

If there’s one thing I’ve learned in my 3 years into IT so far, it’s that management doesn’t want to open the ITSM tool up to do something.  They’re busy with whatever other system(s) that they have to manage.  They may even become desensitized to the “Support Service” emails they receive on a daily basis.  So it’s always a good plan to make things as simple and convenient for them as possible.  It’s what spawned “ApprovalUtil“, which dynamically places catalog variables in requests (so I’m not maintaining a million emails for each catalog item – a number which grows all the time).  In a recent sprint, it’s spawned even more approval utility goodness.

Continue reading

An Exercise in Sensibility – Scheduling the Unschedulable

There’s a really awesome plugin that lets you export dashboards and homepages to PDF in ServiceNow.  But a few of you out there are like me: I (or rather, someone in management) wanted dashboards to be scheduled at a certain day and time.  I put in a HI Ticket (in late October) and was told “that’s not a feature we have right now” and put it to rest for a while.  And today, I had some maintenance time, so I took a whack at it.  And I guess I have a HI Ticket and a FTASK to go update with my findings.

Continue reading

ServiceNow Selenium Tests – The Template Form

As my efforts to provide full “coverage” of the UI I reasonably expect my users to use in ServiceNow, I’ve aimed my attention at the template form.  Templates can be dangerous in ServiceNow, if you let them run amok.  I discussed in a previous post how users can potentially enter bad data combinations, or if they have access to the schedule button can schedule records to be generated on an undesired basis, and created some checks and balances so users could create templates, but not go crazy with them.  Today I’ll examine how to use automation to create templates with the UI, and validate my error messages happen when users enter bad data.

Continue reading

An Exercise in Sensibility – Reminders

If you’ve ever poked around the tables list in ServiceNow, or browsed the ServiceNow wiki for “reminder”, you’ve probably run into the “reminder” table.  This table seems fairly straight-forward at first glance, but a deeper dig brings up several questions.  What is this Reminder Field Name field type?  Why can’t I add fields to it, or  remove fields from it?  Why is the business rule to handle the reminders inactive by default?  What is this “addListener” function?  Why is there no documentation on any of this, and in it’s stead an article to create a custom field?

Continue reading