In this video we will look at debugging tips for troubleshooting service portal configuration issues.
Linked time codes for these topics appear in the YouTube description for this video.
Let's start with client script debugging options.
From the service portal configuration page we can access the widget editor...
... select the widget we want to troubleshoot...
... and access the client script directly.
The console.log command outputs the requested string object to the browser console.
Here in Chrome the console is accessible from developer tools...
... or use the keyboard shortcut "command, option, I."
When used in the client controller this command is native to the browser.
When we add the command to the client script and save it, the script runs again.
And here's the output.
You can also use spUtil.addErrorMessage, addInfoMessage and addTrivialMessage to output a status message at the top of the browser screen.
See the widget API on the ServiceNow developer site for more details.
The data JSON command uses the angular JSON filter to display the content of the data object...
... in an easy-to-read format.
Here we've embedded the command in HTML pre-formatted text tags.
The debugger command, native to Chrome and Firefox, sets a browser breakpoint allowing you to step through a script line by line.
Here the script is paused right before rendering the data message.
Now let's look at some server script debugging options unique to service portal.
Keep in mind that these commands will only work in the server scripts in service portal.
They will not work in the script includes of other applications.
We can use the console.log command in the server script like we did in the client script...
... but in this case it logs server-side JavaScript objects and strings to the browser console.
The SP log command outputs JavaScript objects and strings to a service portal page...
... but it only produces output if the logged in user has the SP admin role...
... or is impersonating a user with that role.
Now let's look at some normal ServiceNow functions that you could also use in server scripts to troubleshoot service portal.
The gs.info, gs.warn, and gs.error commands output text to the syslog database table.
In our example...
... we add a gs.info and gs.warn command to the server script.
Then we refresh the page and enter a value.
When we access the syslog database table and view its list of records...
... we can see the value the user entered as an information entry...
... as well as a warning that the value was invalid.
Like SP util add info message, add error message and a trivial message in the client script...
... the gs.addInfoMessage and gs.addErrorMessage functions output a message or error respectively...
... to a ServiceNow page in the browser.
gs.addInfoMessage is similar to the SP log command we just looked at but it produces output for all logged in users.
Now let's look at context menu tricks that portal administrators can use on a portal page for troubleshooting.
Hold down the control key and click on a widget on a page to open the administrator context menu.
From here you can edit instance widget options...
... access the widget instance in a page editor...
... view the page designer...
... show widget customizations...
... edit widget options and print widget data into the console...
For a peek into a widgets data at the current point in time...
... you can print its data to the console log.
First open the browser console...
... then select one of the following from the context menu...
... log to console scope data or log to console scope.
When we log scope data we only see the data object that was sent over from the server.
Scope on the other hand, can hold a lot more than just the data object.
Any variables created in the client controller that need to be accessed from the HTML template...
... are stored in scope as well.
When we select scope, here's the result in the log.
Here's another trick you can use on the service portal page.
Deactivating or hiding widgets allows you to isolate widgets on a page to troubleshoot issues.
Hold down the control key and click on the widget to open the administrator context menu...
... and select instance options.
If the active checkbox is available on the form...
... you can toggle it on and off to hide and show the widget on a page.
But notice that the active checkbox is not in the form in our example.
We need to open the form in the platform...
... so that we can manually configure the form layout to include the active field.
When we clear the active checkbox, save the form...
... and reload the service portal page...
... the widget is now hidden.
Now let's look at widget diagnostics to help you troubleshoot your service portal issues.
In the portal page that you need to troubleshoot, hold down the "ctrl" key and click any widget...
... the page reloads and widgets are color coded to display their level of customization.
Base system widgets display in green, cloned widgets in yellow, new widgets you've created in blue...
... and customized widgets in red.
The customization level can help you prioritize your troubleshooting.
Customized widgets should be your highest priority...
... because their base system widgets that you've configured.
You can see more about a widget by clicking the information icon.
The options available here depend on the customization level.
In our example, we can compare the code with the base system.
The records of the base system widget and customized widget appear side-by-side.
By clicking the window icon in any code block we can compare the code.
To fix issues you find edit the customized files in the widget editor.
Here we remove extra code from the customized widget.
If you're still experiencing page issues, check your new and cloned widgets next for recent code. changes.
If you cloned a widget prior to a system upgrade, try cloning the widget again to make sure you have the latest code.
Base system widgets are least likely to cause page issues...
But if you're still having issues...
... you can try removing them and adding them again without setting widget options.
For more information see our product documentation, knowledge base, or podcast.
Or ask a question in the ServiceNow community