ServiceNow Code Snippets: Catalog Items And The Portal Widget Data Object

ServiceNow consulting services

ServiceNow Code Snippets: Catalog Items And The Portal Widget Data Object

One of the main expertise areas of ServiceNow consulting services is to have in-depth understanding about portal widget ‘data’ objects and all that it has to offer. You know very well that portal widgets are not just about portal pages, but portal widgets perfectly fit into service catalog items.

Take a quick look at two new methods you can use in ServiceNow professional services to access server data in your portal-based service catalogs.

The above screenshot indicates a catalog item macro variable type and this macro variable can hold a few different objects that can be represented on a catalog item and one of them is a Service Portal widget.

ServiceNow consultancy companies explain that the widget that is displayed in the second and third screenshot, you will notice that there’s a UI consisting of HTML (and Angular).  It is a great way to leverage portal widgets in order to develop robust offerings that go beyond basic catalog design patterns. In this example, we have an input that permits the users to type anything they wish and they can display it on the very first form variable which is populated on Click from form buttons.

Read More :ServiceNow named a leader in Quadrant for IT Risk Management

The user is also given the ability to select from the ‘Populate w/User Data’ drop-down and make it as a popular variable with the current user’s email, title, or username. In the end, the user can mouse over the select any role to make it as a form variable with that role’s title.

  • Input field and data population buttons will populate item 3.
  • Mouse-over menu populate item 3 (‘data’ in object list)
  •  Populated with user text or ‘data’ object button items.
  • Reference field populated through client script call to custom widget API through ‘data’ object.
  • Reference field populated through traditional GlideAjax onLoad.
  • Reference field populated onLoad from ‘data’ object, no client script. Direct from script.

After these listed roles, ServiceNow consultancy firms explain there are three more catalog reference variables (sys_user table) that are pre-populated in three unique ways with the current user. One variable is to populate the same source that generates all the data above, while the other gets populated by a standard GlideAjax call.

Client Scripting (3 ways, but the result is same)

Example #1: With the help of onLoad custom API call populated from portal widget:

With the help ServiceNow professional services it is of custom API generated from portal widget, call methods are linked directly to the widget’s client script that can be connected directly to the widget’s server-side scripting/’data’ object.

  • OnLoad it is important to set the timeout to allow all the page assets to load.
  • The function of instantiation exists in the HTML of the widget and it is available on page load.
  • Associate with the desired method and set its value to variable.
  • Use the JavaScript variable as the form value variables.

As this method ServiceNow application development performs small jobs in the above example, it can be used to initiate a complex data push or pull. In addition, conditional DOM manipulations can be performed in this method.

Populated from GlideAjax

ServiceNow custom applications detail that the standard GlideAjax is shown for comparison. Refer ServiceNow’s documentation to learn more about GlideAjax. Leverage this method to return one or more values through an asynchronous callback function. 

Populated from portal widget with the use of $scope.page.g_form

This code is used in the widget’s Client Controller and no other code is necessary.

  • Set a familiar named object to the scope’s ‘g_form’ object. 
  • Consume the ‘data’ object from the script and called from the widget’s server scripting
  • Additionally, there’s a scope to skip the script

Server Scripting

Working with GlidAjax, it is easy to create and return JSON objects and reach out to non-callable functions.


Conclusion

The widget technique does not replace GlideAjax. This method has no merit outside of the portal. Catalog offerings viewed from the native UI, GlideAjax need to be used. If catalog offerings are viewed from the Service Portal, this method is an option. It is also important to understand that this method uses standard JavaScript, Angular and Glide scripting to maximize ServiceNow’s platform capabilities.

0 0 votes
Article Rating