Attach kb tab not appearing out on the incident ticket when using API

chercm
Mega Sage

when i try to use this patch command to update inc ticket  : 

{"work_notes": "[code]<a title='Warranty coverage details for SCI and DeSc computers' href='kb_view.do?sys_kb_id=e31486b5474321009db4b5b08b9a7164' >KB0000010 : Warranty coverage details for SCI and DeSC computers</a>[/code]"}

the tab for attached knowledge article does not come out : 

 

chercm_0-1702452561946.png

 

 

 

2 ACCEPTED SOLUTIONS

Tai Vu
Kilo Patron
Kilo Patron

Hi @chercm 

You can try the Table API. Let's put the table name as "m2m_kb_task" and the body with the task and knowledge sys_id, it should work.

Sample below.

POST https://<instance_name>/api/now/table/m2m_kb_task

 

 Body

{
    "task": "<task_sys_id>",
    "kb_knowledge": "<knowledge_article_sys_id>"
}

 

Timi_0-1702523575695.png

Timi_1-1702523602574.png

 

Cheers,

Tai Vu

View solution in original post

Hi @chercm 

Yes the task_sys_id above is the record sys_id. There's a couple of ways that you can retrieve the record sys_id.

Timi_0-1703043436828.png

Timi_1-1703043468384.png

 

If you're using scripting with GlideRecord query, you can dotwalk sys_id or use the API getUniqueValue().

 

Also, in the Request Body at the task attribute, you can enter the Incident Number. It should work as well.

 

Cheers,

Tai Vu

View solution in original post

7 REPLIES 7

Maik Skoddow
Tera Patron
Tera Patron

Hi @chercm 

just adding work notes to a record will not trigger any further actions in ServiceNow.

Instead, if you want to see the referenced knowledge article in the related list "Attached Knowledge" you also have to add a record to the m2m table "m2m_kb_task".

Maik

@Maik Skoddow  i managed to get the kb article attached after removing [code]

 

{"work_notes": "<a title='Warranty coverage details for SCI and DeSc computers' href='kb_view.do?sys_kb_id=e31486b5474321009db4b5b08b9a7164' >KB0000010 : Warranty coverage details for SCI and DeSC computers</a>"} 

 but it is appearing as not with the URL on it .

 

chercm_1-1702475298135.png

 

 

chercm
Mega Sage

@Maik Skoddow  i managed to get the kb article attached after removing [code]

 

{"work_notes": "<a title='Warranty coverage details for SCI and DeSc computers' href='kb_view.do?sys_kb_id=e31486b5474321009db4b5b08b9a7164' >KB0000010 : Warranty coverage details for SCI and DeSC computers</a>"} 

 but it is appearing as not with the URL on it .

 

chercm_1-1702475298135.png

 

to add to : m2m_kb_task table how can i do that using API ? 

 

is this possible ? 

 

var kbGR = new GlideRecord('kb_knowledge'); if (kbGR.get('number', 'KB0010023')) { // replace 'KB0010023' with the number of your KB article var incidentGR = new GlideRecord('incident'); if (incidentGR.get('number', 'INC0010023')) { // replace 'INC0010023' with the number of your incident incidentGR.kb_knowledge = kbGR.sys_id; incidentGR.update(); } }

Tai Vu
Kilo Patron
Kilo Patron

Hi @chercm 

You can try the Table API. Let's put the table name as "m2m_kb_task" and the body with the task and knowledge sys_id, it should work.

Sample below.

POST https://<instance_name>/api/now/table/m2m_kb_task

 

 Body

{
    "task": "<task_sys_id>",
    "kb_knowledge": "<knowledge_article_sys_id>"
}

 

Timi_0-1702523575695.png

Timi_1-1702523602574.png

 

Cheers,

Tai Vu