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

Dario_C
Mega Sage

Dear @Chetan Mahajan  & @Manmohan K  ,

Thank you for your answer, the code is work fine, the problem is i can't add more knowledge to the topic, just one for each. This is a normal behavior of ServiceNow, or the problem was the script  ? Maybe i can try NewRecord() than initialize()  ? 

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

Dario_C
Mega Sage

I have fixed the issue , was a wrong mapping of 

            m2mGR.knowledge = knowledgeBaseId;

 here needed to mapping the knoledge's number.

Thanks everyone

Hi Dario,

 

We had the same problem and changed it to current.number but it does not work still we have this: 

mfhaciahmetoglu_0-1706274503725.png

Any idea why?

 

Thank you.

Best,

Firat

Hi mfaciahmetoglu, 

can you post the code of BR and is before or after ?

Thank you