Populate case number on Incident

Sravanthi10
Tera Contributor

Hello everyone,

 

There is a customer case record and using a UI action, we are creating an Incident.

Like, when we right click on the case form and select and click on Create incident, an incident is getting created.

So, once it is redirecting to incident, I see the case number in the Customer cases related tab.

There is also a Case field of reference type on the Incident, and there I want to populate with the respective case number while creating.

Can some one help me how can I do that?

 

below are the screenshots for your reference

Sravanthi10_0-1716377654913.png

 

Sravanthi10_2-1716377692860.png

 

 

Regards,

Sravanthi

 

 

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Sravanthi10 

is the Case field a custom one or OOB?

Also is that UI action an OOB or custom?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sravanthi10
Tera Contributor

Hi Ankur,

 

The case field on the incident is not oob one

and secondly, the UI action when I checked it is showing like, created by admin.

The UI action name is Create Incident on the Case table.

 

Sravanthi10_0-1716383479694.png

 

SNOW BOT
Tera Contributor

Hello @Sravanthi10 , you can retrieve the value of case from the current object in createIncidentFromCase() function at the time of creating an incident as below -

 

createIncidentFromCase(){
//code for creating incident
incidentGr.case = current.sys_id; // current.sys_id will give you the sys_id of case record
incident.insert();

}

 

If my answer solves your question, please mark it as Accepted ✔️ and Helpful 👍 based on the impact.

 

Community Alums
Not applicable

Hi @Sravanthi10 ,

I tried your problem in my PDI it works for me please have a look below solution 

I created UI Action and added below code 

 

var gr = new GlideRecord('incident');
gr.initialize();
gr.sys_id = -1;
gr.u_case = current.sys_id;
gr.insert();
action.setRedirectURL('incident.do?sys_id='+gr.sys_id)

 

SarthakKashyap_0-1716792902063.png

 

I also created I relationship for Related list and added below code 

SarthakKashyap_3-1716793183576.png

 

 

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);
	current.addQuery('u_case', parent.sys_id);

})(current, parent);

 

 

Result 

SarthakKashyap_2-1716793165038.png

 

SarthakKashyap_4-1716793230204.png

Related List 

SarthakKashyap_5-1716793254818.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak