- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2020 12:06 PM
I need to create a form button that will allow go to a URI within servicenow actually it's an interceptor. It's the same interceptor that when you are on a company record and see the open recent cases you can click new button. Since I can not put the Open Recent cases on the other form (it's built off the task table and is already used by the companies form. I just need to put a button that will do the same thing. I know it will be a UI Action but not sure how to do the script for it to a URI. Could someone lend a hand with this?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2020 06:25 AM
Hi Steve,
You are correct about using a UI Action. I built this for an example that takes you from an incident to the Change request interceptor. The "gotcha" comes in getting the URI. Here's the script part of my UI Action
gs.setRedirect("/wizard_view.do?sysparm_wizardAction=sysverb_new&sysparm_stack=change_request_list.do&sysparm_parent=8db4a378c611227401b96457a060e0f4&sys_target=change_request");
The "trick" is to go to the interceptor page and capture the URL. From there trim the front so that you get to the uri section. Then you need to convert the HTML character codes into their actual characters (e.g. %3D is =). Here's the link to a page with those translations.
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2020 10:44 AM
Hi Enrique,
Here's the code that I use
(function(current, previous, gs, action) {
var changeRequest = GlideRecord("change_request");
changeRequest.setValue("type","scheduled");
changeRequest.setValue("short_description", current.short_description);
changeRequest.setValue("description", current.description);
changeRequest.setValue("cmdb_ci", current.cmdb_ci);
var theOwners = new GlideRecord("sys_user_group");
theOwners.get("name", "Change Owners");
var userGroup = new GlideRecord("sys_user_grmember");
userGroup.addQuery("group", theOwners.sys_id);
userGroup.addQuery("user", current.assigned_to);
userGroup.query();
if (userGroup.next()) {
changeRequest.setValue("assigned_to", current.assigned_to);
}
changeRequest.setValue("u_problem", current.sys_id);
var theUser = new GlideRecord("sys_user");
theUser.get(gs.userID());
changeRequest.setValue("location", theUser.location);
var theChange = changeRequest.insert();
current.setValue("rfc", theChange);
current.setValue("state", 6);
current.setValue("u_close_code", "transferred");
current.setValue("close_notes", "Closed by creation of change");
current.update();
var theScript = new IntegraMiscFunctions();
theScript.closeProblemIncidents(current);
gs.addInfoMessage("Change " + current.rfc.getDisplayValue() + " created from problem " + current.number);
action.setReturnURL(current);
action.setRedirectURL(changeRequest);
})(current, previous, gs, action);
We are in a regulated industry so our ServiceNow instance has been validated. In order to access changes, a fulfiller needs to be certified in the process. That's the reason for the part of the code starting with
var theOwners
In the second line, you will need to replace the second parameter because scheduled is something specific to our instance. I suspect you will use standard. Make sure you check for the value and not the label.
Towards the end the two lines starting with:
var theScript
are just invoking some functionality that is specific to our instance and basically makes sure that some BRs around when a problem can be closed don't interfere. When we move an incident or problem to a change we don't leave that incident/change open.
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2020 07:01 AM
"In the URI, the parent sysparm is the sys_id of the source object, in your case the problem."
gs.setRedirect("wizard_view.do?sysparm_wizardAction=sysverb_new&sysparm_stack=problem.do&sysparm_parent=8db4a378c611227401b96457a060e0f4&sys_target=change_request");
When I tracked the sysparm_parent, the sys_id is not the sys_id of the 'problem' table. The sysparm_parent is the sys_id of the interceptor.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2020 07:36 AM
Hi Enrique,
If that redirect is what is going to the interceptor, you will need to add a sysparm to hold your problem's sys id e.g. sysparm_source. That will make the value available to scripting from the interceptor where you can repeat the process. I haven't had to do any type of setup like this so I'm giving you my best idea on how you can accomplish your result.
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2020 07:52 AM
johnfeist,
definitely appreciated your ideas...we are also doing some proof of concept that's why we are trying things.
thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2021 08:22 AM
URL decoding makes me cross-eyed. (I'm halfway there already)
Try doing this:
var decoded = new Packages.java.net.URLDecoder.decode(someURLEncodedString);