Help to relate case to incident

naab
Tera Contributor

Hi All,

 

I have created a UI action button in Case form to create an incident, however in the created incident the case is not related. Script used to create incident as below.

I would appreciate any help.

 

var inc = new GlideRecord('incident');

inc.newRecord();

inc.parent = current.sys_id;

inc.short_description = current.getValue('short_description');

inc.u_parent_case = current.getValue('number');

inc.caller_id = current.getValue('contact');

inc.insert();

gs.addInfoMessage('New incident created: ' + inc.number);

action.setRedirectURL(inc);

1 ACCEPTED SOLUTION

Shubham_Shinde
Giga Guru

Hello @naab ,

There's an oob option to create Incident from Case by installing Customer Service with Service Management plugin which integrates CSM application with ITSM application, and installing this plugin will auto create an UI Action "Create Incident" for Case table using which you can create incident from Case record.
However, if you still need to have a custom UI Action then you can make below changes in your script and it should work!

var inc = new GlideRecord('incident');
inc.initialize();
inc.parent = current.sys_id;
inc.short_description = current.short_description;
inc.u_parent_case = current.sys_id;

var userGr = new GlideRecord("sys_user");  
if(userGr.get("user_name",current.contact.user_name))
	inc.caller_id = userGr.sys_id; //Getting user record from sys_user table because the contact field on Case table refers to customer_contact table instead of sys_user table

inc.insert();

current.incident = inc.sys_id; //Setting the created incident in the field "Incident" on Case
current.update();

gs.addInfoMessage('New incident created: ' + inc.number);
action.setRedirectURL(inc);


If  my answer has helped with your question, please mark it as helpful and give it a thumbs up!

 

Regards,

Shubham
 

View solution in original post

2 REPLIES 2

Shubham_Shinde
Giga Guru

Hello @naab ,

There's an oob option to create Incident from Case by installing Customer Service with Service Management plugin which integrates CSM application with ITSM application, and installing this plugin will auto create an UI Action "Create Incident" for Case table using which you can create incident from Case record.
However, if you still need to have a custom UI Action then you can make below changes in your script and it should work!

var inc = new GlideRecord('incident');
inc.initialize();
inc.parent = current.sys_id;
inc.short_description = current.short_description;
inc.u_parent_case = current.sys_id;

var userGr = new GlideRecord("sys_user");  
if(userGr.get("user_name",current.contact.user_name))
	inc.caller_id = userGr.sys_id; //Getting user record from sys_user table because the contact field on Case table refers to customer_contact table instead of sys_user table

inc.insert();

current.incident = inc.sys_id; //Setting the created incident in the field "Incident" on Case
current.update();

gs.addInfoMessage('New incident created: ' + inc.number);
action.setRedirectURL(inc);


If  my answer has helped with your question, please mark it as helpful and give it a thumbs up!

 

Regards,

Shubham
 

Thank you Shubham, your suggestion worked.