UI action to create child incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2012 12:13 PM
Trying to create something in the UI that will let me create a child incident (one that contains some of the parent's data).
Based on some of the posts I've seen here, I did the following:
var fieldList = 'sysparm_query=active=true^u_inc_type=2';
fieldList += '^parent=' + current.sys_id;
fieldList += '^cmdb_ci=' + current.cmdb_ci;
fieldList += '^u_priority_engserv=' + current.u_priority_engserv;
fieldList += '^u_platform=' + current.u_platform;
fieldList += '^category=' + current.category;
fieldList += '^subcategory=' + current.subcategory;
fieldList += '^u_service_type=' + current.u_service_type;
fieldList += '^caller_id=' + current.caller_id;
redirectURL = 'incident.do?sys_id=-1&' + fieldList;
action.setRedirectURL(redirectURL);
I marked this UI action as being for the Incident table, and as being for the "form context menu".
Two questions:
1. Despite specifying a "parent", the incident that gets created seems never to be linked to the original incident. I observe that the constructed URL has a "parent" value in it, and it looks right, but neither the new incident nor the original are linked to each other in any way, after the new incident is saved.
2. This UI action *still* shows up as a button on the "child incidents" tab, even though I don't want it to. Again, I made the UI action a "form context menu" action (only). How do I get it *not* to appear on the child incidents tab? This matters because, in the child incidents tab, the action's script appears *not* to run in the context of the incident that's on the page... That is, "current" has no values in it, when I get to this UI action from the child incident's tab. It only has values if I select the action from the form context menu.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2012 01:40 PM
I'm not sure if this is exactly what you're asking but here are a couple of suggestions.
1. On the incident form, do you show the related list Incident->parent to see the child incidents?
2. You could add a condition on the ui action, like current.parent.nil()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2012 02:37 PM
Thanks for the reply!
> On the incident form, do you show the related list Incident->parent to see the child incidents?
Not sure what you mean... At the bottom of the form, there's a set of tabs labeled "Affected CIs", "Task SLAs" and "Child Incidents". When I select the "Child Incidents" tab of the original incident, after I've created (or attempted to) a child incident using the steps I outlined above, I do not see the new/child incident in the original incident's Child Incidents list. Moreover, when I view the new/child incident, I don't see the original incident listed as the "parent", either.
Not sure that answered your question, though.
> You could add a condition on the ui action, like current.parent.nil()
Sorry to be dense, but don't know what you mean here, either.
To recap, I've got an incident for which I want to create a child. I want to pre-fill some of the values in the child, though, using data from the original incident. And, I want to do this prior to letting the user finish entering child data.
So, by using the steps outlined in my original post (which I constructed by referring to various answers, here), I wind up with two incidents that aren't related to each other in any way.
My primary concern is to fix that problem. 🙂
My secondary concern is around the presence of the "New" button on the "Child Incidents" tab. If I edit the UI action code for that button, it seems as though the variable called "current" (from which I thought I would be able to retrieve values from the incident form on the top half of the page) never has any data in it. Even current.sys_id is empty. That holds even when I change the "New" button's UI action so that it's no longer "global", but is, rather, applied to the incident table. The only way I can see to get "current" to contain the original incident's data is to make a new UI action, relate it to the incident table, and add it to the form context menu. Since that's the case, I'd like to just get rid of the "New" button on the Child Incidents tab (or, barring that, I'd like to understand what I can do to the "New" button's logic to get access to the data for the incident that occupies the top half of the page).
Does that help?
Thanks again for the reply!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2012 03:19 PM
Hi Klassa,
Here is a more friendly solution to your URL method. Again using a UI Action
// Create new incident record
var incident = new GlideRecord('incident');
incident.parent = current.sys_id;
incident.cmdb_ci = current.cmdb_ci;
incident.u_priority_engserv = current.u_priority_engserv;
incident.u_platform = current.u_platform;
incident.category = current.category;
incident.subcategory = current.subcategory;
incident.u_service_type = current.u_service_type;
incident.caller_id = current.caller_id;
var newIncidentSysID = incident.insert();
Now, depending on what you mean by [quote] Despite specifying a "parent", the incident that gets created seems never to be linked to the original incident[/quote] there are a number of ways to link incidents together.
The first being the parent field, to see any real relationships using this method you need to add a related list to the incident form "incident -> parent" this will show all the incidents which have the currently opened incident as their parent, in other words it will show all the child incidents.
The second is using the task_rel_task table. This is a plugin that you may not have currently activated. Below is an example optional piece of code you can add-on to the above script to add the relationship at the same time.
//OPTIONAL:
// Add an incident -> incident relationship
var taskRel = new GlideRecord('task_rel_task');
taskRel.parent = current.sys_id;
taskRel.child = newIncidentSysID;
// Set the type to "Causes::Caused by" or what ever relationship you want, could be "Parent::Child"
taskRel.type = 'd798ba000a2581020048305ef5287403'; //sys_id of the relationship
taskRel.insert();
To answer your other question of how to prevent the UI Action from appearing on a child incident, I would set the conditions of the UI Action to something like
This way the UI Action will only appear on incidents which do not have a parent set, meaning you cant have child of child incidents.
current.parent.nil()
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2012 06:44 AM
Thanks, all... Got it to work. Seemed to have to set the u_parent_incident field to get the parent/child relationship to work. Not sure if that's due to a customization made to our environment before my time, or not.
Regardless, a related question:
On the "Child Incidents" tab (which indeed appears to come from the "Incident>Parent" mechanism you mentioned; that was already there, and is the part of the page I was referring to when I mentioned "Child Incidents"), there's a "New" button. As discussed, I can get rid of it by changing the condition to something that evaluates to false (like "false", even). Question is, does that affect anything else? I ask because the associated UI action has its "Table" value set to "Global". That leads me to believe that this "New" button shows up elsewhere, and does context-appropriate things... By hiding it, am I going to break something elsewhere, that I'm not even aware of?
Thanks!