TUESDAY, FEBRUARY 07, 2012

Posts Tagged ‘Client scripts’

E

very now and then I come across a question dealing with the order of execution for client-side code (Client Scripts and UI Policies). In my experience, the need to order client-side code is pretty rare and really only applies in a few ‘onLoad’ scenarios and even fewer ‘onChange’ scenarios. Usually, the way that a browser parses and executes client-side code means that the ordering is pretty unpredictable. It’s worth mentioning that this issue doesn’t exist with server-side code precisely because the browser isn’t involved (which is why you can neatly order all of your business rules without issue).

In this post I’ll show you some of the techniques I’ve used in the past to provide some control over the order of execution of client-side code. I’ll also show you a pretty cool trick that you can use to ensure that a piece of client-side code runs before any other client script or UI policy…or after ALL of those scripts finish running.

Learn more ...

H

ave you ever wondered how Service-now does the collapse and expand animations in the application sidebar? This same animation effect is also used when collapsing form sections or displaying service catalog variable hints. I discovered last night how this is done and you can do it to with a simple script!

ServiceNow Collapse-Expand Effect

Learn more ...

O

ne problem I’ve seen a few times is the need to create a new record on the fly in order to populate it into a reference field. This problem recently came up for me with a client I’m working with so I decided to come up with a good solution. An example scenario would be a technician filling out an incident record for a user that doesn’t yet exist in the system. At first glance, the solution seems simple enough…simply navigate to the user form and create the new user, then create your incident record. While that can be done, it’s not always so simple. What if the technician has just spent several minutes filling out the incident and then realizes the caller doesn’t exist? The user would then have to navigate away from that incident record and lose all of the changes, or open an entirely new browser window to create the user and then return and populate the field.

Fortunately, there is a better way if you know how to leverage UI Macros and GlideDialogWindow QuickForms. This article shows a solution that you can use for any ‘sys_user’ reference field in your system. It can also be easily modified and applied to other reference fields as well.

GlideDialogWindow-Add User

Learn more ...

F

orm sections are a great way to segment information on a form into pieces that make sense to be grouped together. The most common example of the use of form sections is the ‘Comprehensive Change’ form. If you want to learn more about how forms, form sections, and views work I HIGHLY recommend a post I wrote a while ago on the topic. When customers use form sections, the need often arises to be able to show and hide that form section with a client script onLoad or on some changed field trigger.
People have known how to hide these form sections based on an ID number (which corresponded to the order of the form sections on the form). This method works fine, but it fails as soon as you add a new form section or change the ordering of your form sections in some way. Because of this, there has long been a need to hide form sections based on the section name or caption. Nobody has been able to figure out a way to do this…until now. Read on for the details…

Learn more ...

I

‘ve answered several questions in the past about the functionality of lock icons in Service-now. Lock icons appear on glide_list and URL fields. The most-common example is the ‘Watch list’ field on the task table. Service-now provides some system properties to manage the default lock appearance of these field types. There are times when a global system property doesn’t really meet the need you have however, and you need to lock or unlock these fields automatically using script. In this article I’ll explain how I’ve done these types of things before.

GlideList-URL-Lock Fields

Learn more ...

T

here are several ways to do time tracking in Service-now. One of the ways used frequently (especially in Incident Management) is the ‘Time Worked’ field. The Service-now wiki describes this functionality. I often see the requirement to have some control over the stop/start of this Time Worked field for customers using this functionality. This post describes the approaches I’ve used in the past to meet this need.

Toggle Time Worked

Learn more ...

W

orking in Service-now, you’ll find that a lot of scripting tasks come down to identifying which fields changed on a form (client-side) or record (server-side). In this post, I’ll show you some different techniques to identify changed fields in both client-side, and server-side scripts. I’ll also show you a way that you can capture changed fields and values and print them in an email notification…without having to check every potential field in a record.
ServiceNow - Changed Fields

Learn more ...

It’s not uncommon in any application to have scenarios where multiple people might be working with a single record at the same time. This is certainly true with Service-now (particularly for records on Task tables). You may have experienced frustration while working with an incident record, making updates, and having some of those updates overwritten a few minutes later because somebody else had the record open at the same time and didn’t know about the changes you had made. Because of situations like this, there is often a need to provide some sort of record lock or alert capability that lets people know when other people are working with the same record.

In the past, you may have used the ‘Simultaneous Update Alert’ script from the Service-now wiki to provide this capability. While that solution works fine, and I’ve used it on almost every engagement I’ve been involved with since it became available, it’s pretty limited in the information it provides back to the end user. You just get a simple alert on record submission…no details, no available actions other than to go ahead and submit or cancel, etc.

I recently had a coworker recommend the use of a UI page to provide a little more flexibility to the messaging that comes with the simultaneous update alert on the wiki. I thought this was a great idea and I had some time over the New Year’s holiday so I started working on it. I’ve finally come up with a solution that I’m happy with and have posted it here in the SNCGuru downloads section as the ‘Simultaneous Update Alert’ update set.

Simultaneous Update Alert

Learn more ...

H

ere’s a very cool (and simple) secret that allows you to show and hide loading dialog screens. These scripts can be run from anywhere in your system that supports client-side javascript.

You’ve probably seen these used in various places in your Service-now instance, most notably in List V2 rendering.


Learn more ...

I

‘ve seen a lot of requests on the forums asking how you can identify the button that got clicked form an onSubmit client script or a business rule. Usually the aim behind these questions is to make some field display or be mandatory based on a button click. While you can use client scripts and UI policy to do these things, there’s no built-in way to identify if a submit came from a particular UI Action. There is a way that’s been floating around for a while that you can do this and while it works, it’s not really the best way.

This post shows how to identify the UI Action that got clicked in an onSubmit script or business rule…the right way. In a single line of code you can return the Action name of the UI action and act on it accordingly.

Learn more ...


Latest Comments

  • Mark Stanger: This linkage all happens for you if you use the task survey plugin. You can look on the wiki for more...
  • Vineeth: I want a way in which if a survey is filled in by the user the response are stored in the survey response...
  • Mark Stanger: This functionality doesn’t connect to an FTP server. See this line in the post above…...
  • Mark Stanger: The report page is back-end XML so there’s no way to directly manipulate the behavior of that...