Let's say you want to auto-fill your Short Description based on the selected Subcategory. First, create a lookup table, then populate the key field, in this case the Subcategory and the auto-filled field, Short Description.
When the user selects the Subcategory of Password on the Incident form, a client script looks up the matching record and sets Short Description equal to Password Reset. Client script settings You could populate multiple fields or even pull Call Script questions into the Comments field so call center personnel gather good information to pass on to a technician.
There are already Assignment Rules, Templates, and Wizards built in that perform similar functions. Do not specify this argument if you want the field label simply colored the specified color. For more information on running server side scripts with the client, refer to GlideAjax. Type: A server side script that accesses a GlideDateTime field. This is a searchable version of the useful field customization scripts. Caution: The customization described here was developed for use in specific instances, and is not supported by ServiceNow Technical Support.
This method is provided as-is and should be tested thoroughly before implementation. Post all questions and comments regarding this customization to our community forum. Description: This code disables HTML tags in descriptions and short descriptions by substituting the tags with harmless versions that won't execute. Description: The following example is for the number field on incident.
The arguments for the flash method are as follows: tablename. Description: This script makes the label of a particular field in this case, Short Description on the Incident Table bold. Description: This onLoad client script makes fields read-only.
For this example, the script makes the following fields on the Incident table read-only: Incident stateImpactUrgencyPriorityConfiguration itemand Assigned to.
It also removes the magnifying glass for the read-only Reference Fields Configuration item and Assigned to. This bypasses the problem of getting the value into the proper format and proper timezone. Description: Toggles the timer field based on a particular field name.The first parameter is simply the name of your section, which should be completely lower-case. Sections including spaces should use an underscore in place of the first space with the rest of the spaces removed.
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. Hide a form section… If I wanted to hide the second form section on my form I could use this script….
Show a form section… If I wanted to show the second form section on my form I could use this script…. The method for hiding a form section by name is really just a slight change to the way that the form section is selected.
Whereas the number-based method returns all form sections in an array, the name-based method selects just that specific form section based on the form section caption. In some cases you might want to automatically select the form section tab as it is shown. You can also do this through client scripting.
Want to learn more about controlling the behavior of tabs and form sections in ServiceNow? Check out these other articles for more information! I took your idea a step further and created 2 UI Scripts that you can call with the name of the section you want to hide or show on any form.
Nice solution, and thanks for sharing. I tried both methods number and named to hide and show a form section On Load and On Change, it worked great. However I had an existing UI Policy to show or hide a new unrelated field based on priority and it stopped working! I deactivated both client scripts and the UI Policy worked again. Has anyone seem similar behavior? Is there a simple way to clear the value of all fields in the section when hidden?
You can check out client scripts on the wiki for more details.Yes they should, though unfortunately this hasn't solved my issue in Geneva with the activity feed showing the incorrect date. Skip to content. Instantly share code, notes, and snippets. Code Revisions 2 Stars 6 Forks 1. Embed What would you like to do? Embed Embed this gist in your website. Share Copy sharable link for this gist. Learn more about clone URLs. Download ZIP. If you can, it is recommended to just sync the text using getJournalEntry.
This script will replicate all Activity log history, Audit records, and Journal table entries so it looks like it originated from the target instance. JournalSyncHelper - Include.
Allows Journal fields Comments, Worknotes to be synced. Senatillaka fruitionpartners. HistorySet grHistorySet. This comment has been minimized. Sign in to view.
Copy link Quote reply. Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment. You signed in with another tab or window. Reload to refresh your session.The primary issue with assignment rules is that they only run as a record is submitted and they only run if an assignment has not been made already to the ticket being saved. Because of this, the person working the ticket always has to make some sort of assignment before saving the record meaning that the assignment rules never get run.
I learned how to work around this issue on one of my very first Service-now implementations and I almost always implement this solution as part of any Incident Management rollout. The out-of-box assignment rules are documented here. This article shows how you can apply the same customizations to your Service-now implementation that I use for my clients. The first step in applying this customization is to create an assignment lookup table that can store all of the different combinations of values used to determine assignments.
Security setup for this table is also included, but is not documented in this article. I usually set my assignment rule up with a very low order value and a condition that ensures it will always get evaluated.
The assignment rule provided in the update set has the following settings….
The final step is to configure the ability to have assignments populate as fields on the form get changed. This is a great functionality and would help a lot. However, I have a few questions which I am hoping you can help me with. I am dealing with a customer who has more than a few hundred assignment rules, so I built them a template where they can import their assignment rules rather than creating one by one.
My questions are:. The way that it works makes it so that you really only have 1 assignment rule per table. You just make the condition on the assignment rule generic enough so that it always gets run for a particular table.
So, for the example you provided, I would have an assignment lookup record with a category, subcategory, and activity issue defined along with the assignment group and person to return. Thank you for your response.
Your solution is wonderful, however I have made several customization to the client instance which will make it difficult to use this. Having that said, how do you think I can use the assignment rules and building them with this complexity. Thank you for your time in advance. With that kind of complexity, I can almost guarantee that the simplest route would be to do some sort of lookup from a single assignment rule script that would handle everything.
Based on my experience, I would never go down the route of having multiple different assignment rules per table again. This solution allowed me to reduce 21 assignment rules to 1 for one of my tables. It was easy to install and easy to modify for a different table and field names. Thanks Mark. I just found and fixed an issue with this functionality that only happens in Internet Explorer.
This is easily one of my favorites. Especially when a client asks for this to be extended to custom fields.
Thanks for kicking butt on this stuff as usual. Thanks for the props! We have multiple locations and all the requests should go to their own contry service desk reps. How can i create a rule for service requests based up on country or location.
That would depend completely on your specific setup. In the end, your assignment rule script would need to set the assignment group like this…. Y es i just went through the catalogog assignment and went through the fulfillment groups.ServiceNow: Reading Work Notes
Hi Mark, i am trying to apply this solution for change request module but it is not working. It work great!If you are new to ServiceNow, or want to know more about scripting, this article may just help you out! In computer science, declarative programming is a programming paradigm—a style of building the structure and elements of computer programs—that expresses the logic of a computation without describing its control flow.
In short, declarative is the easy "low-code" or "no code" type of programming.
ServiceNow Express uses all declarative programming. I believe vendors like Cherwell use declarative primarily as well. Most of ServiceNow uses declarative programming. You don't have use scripting, and you shouldn't if you don't have to.
This is a Client Script. On an Incident, if a user sets the state to 2, and the user has the itil role, sets the assigned to field to the logged in user. This could be used as Background Script. It uses the GlideRecord library to query for incidents with the priority of 5 and category of "inquiry". If the query finds incident, it will print the Incident number to the console.
Journal field type
The if statement will limit that to 1 printed. This is the same as the script in 2. However there is a setLimit statement to limit returned values from the query to 1.
This is the same as the other scripts above, except it uses an encoded query. Encoded queries are a similar way to write query statements, but not always applicable in all situations.
This is like all the scripts above, except uses a while statement to return multiple values. This script uses a get method to return a value. Business Rule. This script adds an information message to the form to Accept a Solution.
Missing the grIncident. Without that, nothing will happen.This article describes the various methods you can use to display information messages to the users accessing your ServiceNow system. Client-side UI Messages.
The following methods are designed for use in client-side scripting primarily client scripts and UI policies. As such, they are used on standard forms and on catalog forms and can run on load or submit of a form, or on change of a field value. There is no way to remove form info and error messages individually. Type may be either "info" or "error. A global property glide.
Optional: Set scrollForm to false to prevent scrolling to the field message offscreen. Parameters: input - specifies the name of the field or control. Parameters: input - specifies the name of the field. If true, all messages for the field will be cleared; if false or empty, only the last message will be removed. Optional: Provide type to hide only "info" or "error" messages. Parameters: widgetName - Specifies the element with table name.
Although messages will always be displayed client-side, they are often initiated from a server-side script like a business rule, record producer script, or script include.
Messages initiated from server-side scripts can appear at the top of any form or list and are typically triggered by a database action such as a record insert, update, or delete. Can also include HTML in the message! Note that I've replaced the greater than and less than symbols with brackets in the HTML usage example to get it to display correctly here. You'll need to change the brackets back to standard HTML to get it to work in your instance.
UI Notifications are an unusual class that can be used for refreshing elements such as the navigation pane or for displaying messages in response to changes in database tables. For more information about UI Notifications, check out the following articles:. No simple way to change the background color, but you can change the text color by adding HTML to the message as shown in the example above. Is there a table or doc anywhere that has all the possible Error and Warning messages listed?.
All you need to do in most cases is examine the code in those places to determine where the error message originates from. I am getting an error when attemping to apply CSS to the info message in your example.
Looks like the support for this in client-side messages has been removed in the Geneva release. Mark, is there a simple way to make the showFieldMsg messages permanent? For example, if I add one to an email address field then you type something in that field and blur it, the message goes away. I want it to stay there permanently. Is there a way to extend the addInfoMessage duration? I was hoping it would take an additional parameter like the number of ms or seconds to keep it up without requiring interaction.This is an extremely useful feature, but there are times when you need to override this audit process.
Unfortunately, the process of deleting or updating audit, activity, or journal entries is fairly difficult to perform, and even more difficult to remember. First, a little technical perspective as to why this solution is helpful. While doing this, you would need to be extremely careful about how you query the information since all three tables can be very large and accessing them incorrectly could bring your system to its knees.
This solution provides a single, consistent UI action-driven method that keeps you out of the audit tables and updates all of the necessary places in one click. It also includes a confirmation dialog to prevent accidental updates. Deleting audit or journal entries can be accomplished by adding a new UI action with the following settings. Then, simply open the history record to modify and delete or update accordingly!
Works fine for me What I mean is: It Seems to me this option already is available in the instance itself. Maybe it came with a recent patch of release? I think you must be seeing something else then. If you check out a ServiceNow demo instance running the latest code, no such UI action is available. When I go to the demo instance there is now way I can delete history lines like I do in our instance.
Good job. I just ran through deleting an entry from the history list. But the entry still viewable in the journal and audit lists. But if you just want it removed from public view, this seems to be fine…I think…. What if the audit entry is an email? We have had cases where data like a password was placed in there and sent. Also, does this work on berlin? I tried the code there for the update and it says it updates but when you look at the entry — it reverts back to its prior entry it does not keep the update.
You could add a defined related list to show those in the history set form if you wanted easier access. I have been doing this quite a few times recently, and it has been a multi step process: 1. So, I am glad to see that I should be able to accomplish the same results with A ui action.
Thanks Mark. I now have a situation where a user record had the incorrect name for a brief while, and after it was brought to my attention and corrected there was a task that had an activity log entry from several months ago from work done by that user which had the incorrect name when viewed by a caller. When viewed by myself, the name was correct.
If I delete that history record and let the system re-create it will it also resolve this issue? This is a useful tool. Just as stated above sometimes information is added that should not be in a case and this will help those times. I also agree with there should be a strict change management process before performing this action. Is this meant to exclusively be for journal fields then? For journal fields it will update the journal entry appropriately and history.
I was looking for the same behavior on both the new and old fields actually for fields like short description or description on the history line. I found your posting helpful in a different application.
Can you tell me how this value is generated and how I can generate valid values? I have implemented this in our Fuji version of ServiceNow and its not working.
Button appears, allows me to update and the correct confirmation message appears. But when I submit modify or delete the original version is still stored.