The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Make a script only target a specific form view

palmen
Tera Guru

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.

18 REPLIES 18

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


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


-Anurag

mike_donathan
Kilo Guru

Fredrik Palmqvist



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!


});


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.


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



1.JPG


2.JPG


3.JPG





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