Make a script only target a specific form view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2015 05:36 AM
We have a resolve dialog to be able to close mutliple incidents at the same time.
The form view for this has 5 fields you need to fill in.
In the field Ticket type I want to hide one of the values. Is this possible to do?
I've tried to make a client script like this, but it doesn't work.
Active: True
Global: False
View: resolvedialog
Type: onLoad
Table: Incident
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.removeOption('u_ticket_type', 'srq')
}
If I try the same script but make it global, it'll remove the option srq for all views so the actual script seems to be working, it's just not targeting the form view I want.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2015 07:20 AM
How do I target a specific form view with a read acl?
And how do I hide a value in a field with an ACL? Never tried that before
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2015 07:40 AM
even i haven't done it for a choice list....will require RND. It will be difficult by this i guess.
Getting the view is not the issue, removing the field is...instead of choice has this been a lookup then it would be cakewalk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2015 08:11 AM
You can do this by adding a callback function to the GlideDialogForm to remove the option when it renders. Take a look at the sample code below, it should work for you. I tested this on my demo instance in a UI action, and was able to remove choice options.
//Create and open the dialog form
var dialog = new GlideDialogForm('Close Incident', 'incident'); //Provide dialog title and table name
dialog.setSysID(-1); //Pass in sys_id to edit existing record, -1 to create new record
dialog.addParm('sysparm_view', 'resolvedialog'); //Specify a form view
dialog.render();
//Callback removes choice values from 'u_ticket_type'
dialog.setLoadCallback(function(iframeDoc) {
// To get the iframe: document.defaultView in non-IE, document.parentWindow in IE
var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;
dialogFrame.g_form.removeOption('u_ticket_type', 'srq'); //This is where the 'magic' happens!
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2015 12:58 AM
Thanks for the code, it sure do remove the srq option for ticket type.
Problem is when I put this in our current UI Action to trigger the GlideDialogWindow from a list choice, the result is as soon as an incident form or list is loaded it'll popup this window,
When chosing the original Resolve Incidents from the list choice, it still has all the options for ticket type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2015 01:35 AM
I just can't get the code above to work.
If I add it to a form button it works fine, but with a form button I can't resolve multiple incidents.
What I have at the moment is the following (this is functionality that has been working for 3 years before this new requirement)
UI Action: Resolve Incidnets
Business Rule: resolve_multiple
Form View (Incident): ResolveDialog
Is it still possible to use the callback function described by Mike Donathan ?
If possible where should I put it to get it to work? I've tried to put it into the script section but that won't help since it'll always pop-up when loading an incident form.
Our solution is from the wiki I suppose Closing Multiple Incidents - ServiceNow Wiki