- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
3 weeks ago - edited 2 weeks ago
< Previous Article | Next Article > | |
Link to previous article | Link to next article |
Overview
This guide is written by the ServiceNow Technical Support Performance team (All Articles). We are a global group of experts that help our customers with performance issues. If you have questions about the content of this article we will try to answer them here. However, if you have urgent questions or specific issues, please see the list of resources on our profile page: ServiceNowPerformanceGTS
This article is written to discuss common best practices that can be used to avoid performance issues with ServiceNow's Next Experience products. These products include Configurable Workspace, UI Builder, Unified Navigation, Portal Experiences and more.
You can find out lots of great information about Next Experience at the Community Product Hub here: Community Product Hub for Next Experience [Official ServiceNow Community site]
To understand about some of the tools available to troubleshoot performance issues in Next Experience see the page How to troubleshoot Failing Transactions in Next Experience Workspace or Portal Experiences - KB1640...
Table of Contents
- Consider Validating Data Binding Conditions for Data Resources
- More to come...
Consider Validating Data Binding Conditions for Data Resources
This issue can unfold many ways. ServiceNow allows Data Binding to occur on many different types of Components in Next Experience. If your custom component is assuming a valid input to the data binding conditions, but that input is not present at the time the Data Resource executes, it could have unpredictable results. What follows is a specific discussion of how this issue might look for the "Look up" Data Resources, and an explanation of a design pattern to allow validation prior to executing the Data Resources.
The "Look up a single record" or "Look up multiple records" Data Resources (sys_ux_data_broker table ) allow users to search and retrieve specific information from ServiceNow's database based on the provided search criterion. They can be added through UI Builder. Behind the scenes, these Data Resources use GlideRecord. So, all of the performance implications of a GlideRecord operation also apply to a Lookup. If you've read our other blog post Performance Best Practices for Server-side Coding in ServiceNow [Community blog by SN] perhaps you recall that the number one cause of performance issues we see in ServiceNow is undefined or null variables being passed to GlideRecord. Well, since Lookups calls GlideRecord in the background, this same principle exists in Lookups as well.
See All About Data Resources in UI Builder, by Brad Tilton (ServiceNow developer advocate)
How to validate your bind variables
Select the Data Resource you want to add. Click "Add". After that, one of the first choices you will need to make is when to evaluate the data resource. You can choose to have the data resource evaluated immediately on page load (eager) or whenever one of the bind variables is updated (explicit).
If you choose the default option, "immediately on page load", then there will be no opportunity to validate your bind variables before execution of the Data Resource. If your Data Resource executes and your bind variable has not been set, instead of fieldName=<valueYouMeantToBind> the query will execute with the condition fieldName=null. If there are 10 million records with fieldName=null, then this could cause a really slow query and annoy your users. So, if you want to do validation, you should select "explicit".
Next, you need to define an event handler that will trigger the Data Resource execution by updating your bind variable. One way would be to define a Client Script that handles the "body" component's "Page ready" event. In the script you would validate that the data you want is available and only update your bind variable if all the data is present. See Creating An Event Mapping [Official ServiceNow Dev].
Note that the "Only when invoked" option is a little confusing. You might think this means you will need to trigger your Data Resource through a function call somewhere, but that is not the case. The way that your Data Resource will be invoked is whenever the bind variables in the conditions are updated. Take a moment to consider what that means. If you are using bind variable(s) that are frequently updated, your Data Resource will get invoked many times. This could be unwanted and cause performance issues. So you need to figure out a way to only change the bind variables when you want your Data Resource to be updated. See the following community question that discusses this dilemma:
In summary, if you are writing a custom Next Experience page, consider if you should add validation for some of your bind variables. Given the added overhead of writing the extra Client Scripts and Event Mappings, you might find that this process is too time consuming to do every time. If you are already hitting performance issues due to missing validation then adding validation is an obvious solution, but sometimes adding validation before you hit an issue would be a good use of time. For example, if you know that the bind variable you are using could potentially be blank or undefined at runtime, you should probably add some type of validation. Also, if you are writing your page against a very large table (1 million rows or more) this makes it more likely that you could hit a slow query when one of your bind variables is invalid. The solutions above are not necessary for every situation, but we wanted to explain this pattern because we have observed it causing issues for many customers.
< Previous Article | Next Article > | |
Link to a previous article | Link to the next article |
- 286 Views