- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2023 03:29 AM
Hi Guys,
I'm doing an business rule on "after" , insert on Kb_knowledge Table, when a new KB is created I need to write a new record on m2m_connected_content, because I need to attach a kb to the current topic on employee( topic and kb_base have the same name). From the log i retrieve correctly the variables, but the record didn't created on m2m and i have this error : " ErrorContent can not be associated to the same topic more than once. "
Here the Code of my Business rule:
(function executeRule(current, previous /*null when async*/ ) {
gs.log("m2m_connectedINIZIO");
/***********************************/
var knowledgeBaseName = current.kb_knowledge_base.getDisplayValue();
var knowledgeBaseId = current.kb_knowledge_base.sys_id;
var topicGR = new GlideRecord('topic');
topicGR.addQuery('name', knowledgeBaseName);
//topicGR.addQuery('sys_id', knowledgeBaseId);
topicGR.query();
gs.log("m2mQuery " + topicGR.addQuery('name', knowledgeBaseName));
gs.log("m2mQueryID " + topicGR.addQuery('sys_id', knowledgeBaseId));
if (topicGR.next()) {
var topicName = topicGR.name;
var topicSysId = topicGR.sys_id;
}
gs.log("m2mTopicNAME: " + topicName); //ok
gs.log("m2mTopicSYSID: " + topicSysId); //ok
if (topicGR.isValid()) {
var m2mGR = new GlideRecord('m2m_connected_content');
m2mGR.initialize();
//m2mGR.newRecord();
m2mGR.topic = topicSysId;
m2mGR.content_type = '4c32a92153622010069addeeff7b12a3';
m2mGR.knowledge = knowledgeBaseId;
m2mGR.insert();
gs.info("Nuovo record inserito in m2m_connected_content");
gs.log("m2mASSEGNATOPIC: " + m2mGR.topic); //Ok
gs.log("m2mKnowledge: " + m2mGR.knowledge); //Ok
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2023 04:02 AM
You can associate content from multiple knowledge categories to a topic in the taxonomy.
Refer below docs link -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2023 03:37 AM
Hi @Dario_C
Before inserting record into m2m_connected_content table, do a check in m2m_connected_content table in your script to verify if the kb is already associated to the current topic
This should resolve the issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2023 03:46 AM
Hi @Manmohan K
Thank you for your answer, yes, i have deleted the old kb to the topic, and now is work .
But can i associate more knowledge to the topic ? Or Just one ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2023 03:48 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2023 03:51 AM
Hello @Dario_C ,
try this
(function executeRule(current, previous /*null when async*/) {
gs.log("m2m_connectedINIZIO");
/***********************************/
var knowledgeBaseName = current.kb_knowledge_base.getDisplayValue();
var knowledgeBaseId = current.kb_knowledge_base.sys_id;
var topicGR = new GlideRecord('topic');
topicGR.addQuery('name', knowledgeBaseName);
topicGR.query();
gs.log("m2mQuery " + topicGR.addQuery('name', knowledgeBaseName));
if (topicGR.next()) {
var topicName = topicGR.name;
var topicSysId = topicGR.sys_id;
gs.log("m2mTopicNAME: " + topicName);
gs.log("m2mTopicSYSID: " + topicSysId);
var m2mGR = new GlideRecord('m2m_connected_content');
m2mGR.addQuery('topic', topicSysId);
m2mGR.addQuery('content_type', '4c32a92153622010069addeeff7b12a3');
m2mGR.addQuery('knowledge', knowledgeBaseId);
m2mGR.query();
if (!m2mGR.hasNext()) {
m2mGR.initialize();
m2mGR.topic = topicSysId;
m2mGR.content_type = '4c32a92153622010069addeeff7b12a3';
m2mGR.knowledge = knowledgeBaseId;
m2mGR.insert();
gs.info("Nuovo record inserito in m2m_connected_content");
gs.log("m2mASSEGNATOPIC: " + m2mGR.topic);
gs.log("m2mKnowledge: " + m2mGR.knowledge);
}
}
})(current, previous);
Kindly mark correct and helpful if Applicable