- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2018 10:46 AM
Hi guys, I have created a new UI action (code below) to create a Defect from the Inc form.
We have an Inc related list on the Defect form (as well as a custom field 'Defect' on the Inc form which is successfully being set by the new UI action).
I'm having a real blank moment but I just want to know the code needed to reference the existing INC in the Defect related list of incidents??
Furthermore what's the best way to prevent a Defect being created from an Inc, if this has already been done for that Inc (i.e. if 'Defect' field already has a value)?
I.e. we want to allow multiple incidents to be referenced to a defect (that will show on the related list) but only one defect per incident (via the custom field 'Defect').
Many thanks,
DS
UI action code (it's working bar the above requests):
function onSubmit_Defect() {
var response = confirm('Create a defect record?');
if (!response){
return false;
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'createdefect'); //MUST call the 'Action name' set in this UI Action
}
if(typeof window == 'undefined')
create_defect();
function create_defect(){
var defect = new GlideRecord("rm_defect");
defect.business_service = current.business_service;
defect.u_service_category = current.category;
defect.cmdb_ci = current.cmdb_ci;
defect.short_description = current.short_description;
var sysID = defect.insert();
current.u_defect = sysID;
var mySysID = current.update();
gs.addInfoMessage("Defect " + defect.number + " created");
action.setRedirectURL(defect);
action.setReturnURL(current);
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2018 12:21 PM
Open the Defect form, navigate to Configure->Related List and select Defect -> Incident. All the related list are OOB, you just need to add that related list.
Also to not allow users to create another defect from the incident, just add a condition in ui action,
current.u_defect==''
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2018 04:33 AM
Hi Kalyan, could you please expand on the initialise comment - why and where is this needed please?
As metioned the UI action seems to be working fine I just need to know how, when the 'Defect' is created from the INC, I can make the INC number, reference in the Incident related list which is on the Defect form. The Defect number is already being successfully set on the INC form (in the custom u_defect field) via this line in the code:
current.u_defect = sysID;
Thanks!
DS