The CreatorCon Call for Content is officially open! Get started here.

Insert on m2m_connected_content doesnt work

Dario_C
Mega Sage

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.  "

Dario_C_0-1688984964025.png


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);

 

1 ACCEPTED SOLUTION

Manmohan K
Tera Sage

@Dario_C 

 

You can associate content from multiple knowledge categories to a topic in the taxonomy.

Refer below docs link - 

https://docs.servicenow.com/bundle/utah-employee-service-management/page/product/employee-center/tas...

View solution in original post

14 REPLIES 14

Hi @Dario

 

Thank you for your swift reply. Here is our code: (on After)

 

(function executeRule(current, previous /*null when async*/) {

    // Create a new record for the m2m_connected_content table
  var m2mRecord = new GlideRecord('m2m_connected_content');
 
  m2mRecord.initialize();
  // Set the values for the fields
  m2mRecord.setValue('content_type', '4c32a92153622010069addeeff7b12a3');
  m2mRecord.setValue('knowledge', current.display_number); // we also tried here current.number but it did not work either
  m2mRecord.setValue('topic', '19d6fa2793a571100c7d72f48aba103b');
 
  // Insert the new record
  m2mRecord.insert();



})(current, previous);
 
Best,
Firat

Hi Firat,

I think the problem is that 

m2mRecord.setValue('content_type', '4c32a92153622010069addeeff7b12a3');

actually this is a sys_id of my Content type field on m2m_connected_content . So i think you need to create a your content type and try to put there  the sys_id.

 

Let me know ,

 

Dario

That is the OOTB sys_id, so same for us as well. The problem for us is the first column on my SS, it has always the same name and therefore, system sees the duplicate entry. We could not find a way to update correctly that first column.

On Which Table the Business Run ? My Br runs on Kb_knowledge table . 

Yes, kb_knowledge as well!