Create Attached Article Related list Same as for Interaction Record as in Incident

Baker1
Tera Guru

How to Create Attached Article Related list Same as for Interaction Record as in Incident Records related list. 


When An KB Article is attached to Work notes in interaction record. Need to Visisble KB Article in Attached Knowledge Related list in interaction records. 
It is OOB For Incident

3 REPLIES 3

Ethan Davies
Mega Sage
Mega Sage

Out of the box, this is achieved by creating a Relationship record which then allows the 'Attached Knowledge' Related List to exist on the Incident record.

EthanDavies_0-1701981102344.png

The code from that Relationship record looks something like this:

(function refineQuery(current, parent) {
	var attachedKBIDs = [];
	var gr = new GlideRecord("m2m_kb_task");
	gr.addQuery("task",parent.sys_id);
	gr.query();
	var count = 0;
	while(gr.next())
		attachedKBIDs.push(gr.getValue("kb_knowledge"));
	
	current.addQuery('sys_id', 'IN', attachedKBIDs.join());
})(current, parent);

At this stage, the big takeaway is that the actual record that states an Incident has a relationship with a Knowledge Article is stored in the m2m_kb_task table. This stores instances of Knowledge being attached to Task records. The Incident take extends Task, so those are stored in that table.

 

Out of the box, there are various tables that store the relationship between a Knowledge Article and some other table, you can see them in the list of tables. They all start with m2m_kb...

EthanDavies_1-1701981313450.png

No such table exists for the Interaction table out of the box, so you will need to create one. You can model it on the m2m_kb_task table. Once you create that table, you need to create a Relationship record as I showed in my earlier screenshot, and then the Related List will be available for you to select.

 

Let me know if you run into any issues.

Baker1
Tera Guru

Hi @Ethan Davies 
Thank you for quick reply
How can we model it m2m_kb_task
Could you please provide me with screen shot

@Baker1 Okay, so following these steps should get you there, or at least pretty close. If these do not make sense to you then you will need to work with someone more technical to help you build it.

 

Step 1: Create a new table in ServiceNow called Knowledge Applied to Interactions.

EthanDavies_1-1702049784732.png

Consider naming your table something similar to the existing m2m table, something like u_m2m_kb_interaction.

 

Step 2: You're going to need to create several fields here, I suggest using the fields on the m2m_kb_task table as a reference for this.

EthanDavies_3-1702049935383.png

 

Step 3: Create a Relationship record for your table. Please note this is an example, the names of your Table and the field you are querying (the field that stores the interaction reference) on that table may vary depending on how you have configured it.

 

EthanDavies_4-1702050265277.png

Code snippet for this step:

(function refineQuery(current, parent) {
	var attachedKBIDs = [];
	var gr = new GlideRecord("u_m2m_kb_interaction");
	gr.addQuery("interaction",parent.sys_id);
	gr.query();
	var count = 0;
	while(gr.next())
		attachedKBIDs.push(gr.getValue("kb_knowledge"));
	
	current.addQuery('sys_id', 'IN', attachedKBIDs.join());
})(current, parent);

 

Step 4: Create a UI Action to attach knowledge to the interactionA new contextual search UI Action will need to be created, with a custom script to attach to interactions, so that whenever the Attach UI Action is clicked, a new record will be inserted into the m2m table.

 

You will need to figure this one out yourself, but you can create a UI Action for either the workspace or the Platform UI (depending on where you're using interaction) that will essentially show a pop-up that asks you to select a Knowledge Article to associated with the Interaction record. Once you click 'submit' on this pop-up it should then create a record in your new m2m table that we created for the interaction record.

Step 5: Covering additional bases (Optional). There is already an existing method out of the box for associating Knowledge Articles to Interactions, but it's not super useful for us and is designed to store instances of Knowledge Articles being used in Virtual Agent when a user starts a chat (an interaction).

 

The table is called interaction_related_record and I recommend creating a Business Rule or Flow on this table that will automatically create an entry in the new m2m table when a record is added to this table (for the knowledge type only). You will need to consider deleting and updating if you want to keep both records in synch.

 

Step 6: Add the Related List that has now been created from your work in Step 3 to the Interaction form. Be careful in which view you add it, if you want it to be visible on the Workspace, add it to the Workspace view.

 

I think the above should be a good implementation guide and help you to achieve your requirements. Good luck!