UI Action to Create a Record in another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2009 07:17 AM
Hello,
I am wanting to create a new Release record off the back of an Incident. I have therefore written the UI Action below however it appears to take me back to a list of all Incidents therefore my UI Action is not working correctly, its not even creating my release.
NOt sure what I need to set for my GlideRecord in the first line. I have used "release_project" and "release" without any joy.
Further to this I have created a new view which is test_release - not sure where I need to fit this into my UI Action?
Here is the UI Action I have written:
var prob = new GlideRecord("release_project");
release.short_description = current.short_description;
release.cmdb_ci = current.cmdb_ci;
release.priority = current.priority;
var sysID = release.insert();
current.release_id = sysID;
var mySysID = current.update();
gs.addInfoMessage("Release" + release.number + " created");
action.setRedirectURL(release_project);
action.setReturnURL(current);
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2010 07:16 AM
Sorry I have not worked a lot with the outage table at this point so I am not sure what you are populating from the Incident and what you are populating back to the incident from the outage. Take a look at the below and let me know if you are doing something similar. If you post the UI Action I can take a quick look at that too.
var outgr = new GlideRecord("cmdb_ci_outage");
outgr.begin = current.opened_at;
outgr.cmdb_ci = current.cmdb_ci;
outgr.insert();
gs.addInfoMessage("Outage" + outgr.sys_id + " created");
action.setRedirectURL(outgr);
action.setReturnURL(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2010 10:34 AM
Almost. However, used you script and it worked perfectly. Thank you so much, I've spent ages on this and you've sorted it out in a matter of minutes.
Cheers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2013 04:51 AM
I have a customer object with u_ customer_id in customer table. I like to create an order for this customer by UI Action button.
Following code creates new order for the costumer but it is not linking the newly created order with parent customer. What am I missing here? Please help.
var ord= new GlideRecord("u_order");
ord.u_customer_id = current.u_customer_id;
var sysID = ord.insert();
//I do not have u_order_id column in customer table. DoI need it? How do I create it? following code (commented) is copied from UI Action "Create Problem" script.
/*
current.problem_id = sysID;
var mySysID = current.update();
*/
gs.addInfoMessage("Order " + ord.number + " created");
action.setRedirectURL(ord);
action.setReturnURL(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2013 06:34 AM
From the sounds of it you are looking to have a customer record and be able to have multiple orders off of it. If this is the case, I would make sure that you have the "Customer ID" field on the Order table setup as a reference field pointing to your customer table and not a string field. Setting it up this way you will not need to link back to the Order from the Customer as the Orders are providing this link. The best way to do this is to either delete your original field called Customer ID if you have not yet been using the field in production and create it again as a reference field or to add a new reference field with a slightly different name, something like Customer would work if it is not already in use on the Order table. Use the links below for adding a new field if you are unsure how to do this.
What you will need to do then is go to the Customer page and add a related list that shows the orders where the Customer ID is the current customer. This will add a list at the bottom of the record that shows all the orders from that customer and gives you a link to navigate to those orders. If this is what you are looking do do your code would change a bit to something like the below.
Code Option for one to many:
var ord= new GlideRecord("u_order");
ord.u_customer_id = current.sys_id; //this change sets the reference field with the sysID of the current record
var sysID = ord.insert();
gs.addInfoMessage("Order " + ord.number + " created");
action.setRedirectURL(ord);
action.setReturnURL(current);
If you are looking instead for a one to one relationship between the customer and order, we would need to add that new order ID field to the customer record. Use the links at the bottom to see how to do this. Once this is done you can have one order at a time tied to your customer record. The code would be like what you had with a slight change.
Code Option for one to one:
var ord= new GlideRecord("u_order");
ord.u_customer_id = current.u_customer_id; //Set to the original field if no changes are made to it
var sysID = ord.insert();
current.u_order_id = sysID; // Set the field name here to whatever you name the field
current.update();
gs.addInfoMessage("Order " + ord.number + " created");
action.setRedirectURL(ord);
action.setReturnURL(current);
Links to check out:
Adding fields to your form
Refrence Fields
Adding a related list
Let me know if you have any questions on this one or if you are looking to do something other then the examples I have here.
Hunter Wolf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2013 01:38 PM
Thank you for the response.