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

Have you put the code inside the UI action's script as below? Have you selected the client checkbox on the ui action?



function functionname()


{


code


}


The Client checkbox is checked (se screenshot above)



In our current UI Action I tried with the following in the script section but still doesn't help. I'm not good at this but I assume the Onclick: showQuickForm('ResolveDialog','resolve_multiple') has something to do with it



function test() {


  //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!


  });


}


Onclick should the name of the function defined in the script .. In this case, it should be test


With the code above it'll create a new incident instead of resolving the marked incident.


We get some other issues as well since the close notes are read only unless state has changed to Resolved.


The same issue doesn't occur with the showQuickForm in OnClick.