When testing ServiceNow, you often need to adjust your approach, this is largely determined by the application you’re working on.

During my experience at SPOC, working with many different clients and a variety of applications, there was always a need to follow a certain workflow to reach a result that I needed to test.

To test the required acceptance criteria of a story, it might take a tester up to an hour to follow a whole workflow, until they arrive at the step that needs to be checked.

Testing in ServiceNow, an Example

A tester needs to get to a part of the process to test certain functionality against the acceptance criteria of a story, related to the ‚Status Field‚.

Frequently the tester might only see ‚read-only’ fields related to the status of an Incident, Problem, Change or any other ‚status field’ in custom applications.

The status is responsible for the workflow path that the process has to follow.

How to deal with this scenario? We can use ServiceNow Client Scripts to help.

Let’s suppose that we need to go from Assigned State to Invite Sent:

Testing ServiceNow Application Status Assigned

As is visible, the field is ‚read-only’, so the only way to change it is to follow these steps:

  1. First check the name of the field by clicking the right mouse into the field Label: (Sometimes this field might have a very easy name, or similar to the label, but in many other cases depending on the application field name might be different from the label.)Testing ServiceNow : Showing the state of a process
  2. Next step is to find out what is the value of the choice that you need to change. Every status field has one or many choices. Right click on the field status, and chose option show choice list.Testing ServiceNow: Showing the Choice list of a field
  3. Search for the label you want in this case, ‚State’.Testing ServiceNow: Showing the value of a field The value of this field is 104, which means that putting the value in the code will produce the Invite sent state.
  4. After you have the name of the state and the value of the choice you want, go back to the form of the request and press in the keyboard CTRL + SHIFT + JThis will open the JavaScript Executor window.
  5. Now you need to write the code below:  g_form.setValue(‚state’,”104″);
  6.  Click Run my Code

Testing ServiceNow: Running code in the JavaScript Executor

Automatically the value of the field will change to Invite Sent.

Conclusion

This method will be useful and can save time in many cases, especially when skipping some of the states of the workflow will not cause a problem; as they’ve already been tested.