How to set "Parent ID" field in Knowledge Category table using Scheduled Job script?

Dhanakoddi
Kilo Expert

Hi,

I need to create new Knowledge Category by setting Parent ID field in kb_category table using a scheduled job script.

I have the sys_id's of the both main and sub category fields.

Main Category in kb_knowledge_base table is IT Operations, sys_id c8c0005fdb947a84f6ef7016bf9619b9

Sub Category in kb_category table is Application Summaries/Runbooks, sys_id 673ee506db9cbb886e206154ca9619c7

I used below script to set the value in Parent ID field but it updating as empty only...

   var new_cat = new GlideRecord('kb_category');
   new_cat.initialize();
   new_cat.label = "*****";
   new_cat.value = "*****";
   new_cat.parent_id.sys_id = "673ee506db9cbb886e206154ca9619c7";
   //new_cat.setValue('parent_id', '673ee506db9cbb886e206154ca9619c7');   
   new_cat.setValue('table_name', 'kb_category');
   //new_cat.setDisplayValue('parent_id','Knowledge Category: Application Summaries/Runbooks');
   new_cat.active = 'true';
   new_cat.insert();

 

Can anyone help, how to set Parent ID field using a script in Scheduled Job?

 

Thanks in Advance!

1 ACCEPTED SOLUTION

Dhanakoddi
Kilo Expert

The below script is working fine for updating parent ID field in the Knowledge Category table

var new_cat = new GlideRecord('kb_category');
  new_cat.initialize();
  new_cat.label = "*****";
  new_cat.value = "*****";
  new_cat.parent_table = 'kb_category';
  new_cat.parent_id = '673ee506db9cbb886e206154ca9619c7'
  new_cat.active = 'true';
  new_cat.insert();

View solution in original post

3 REPLIES 3

Tony Chatfield1
Kilo Patron

Hi, I would have thought creation of a new ‘unique’ Knowledge Category was a 1 off non reoccurring event and so the need to use a scheduled job seems unusual.

Is your new kb_category record created from your code without the parent_id or not created at all?

parent_id = ‘your_sys_id’; is probabaly thre way I'd try to apply it, have you confirmed it’s the correct sys_id?

Perhaps try manually creating a record and once saved you can validate your values by looking at the xml.

Hi,

kb_category record is creating using the scheduled job script, that is working fine. But only the parent ID field is not updating

I tried below code, but this also not working

new_cat.parent_id= '673ee506db9cbb886e206154ca9619c7';

Dhanakoddi
Kilo Expert

The below script is working fine for updating parent ID field in the Knowledge Category table

var new_cat = new GlideRecord('kb_category');
  new_cat.initialize();
  new_cat.label = "*****";
  new_cat.value = "*****";
  new_cat.parent_table = 'kb_category';
  new_cat.parent_id = '673ee506db9cbb886e206154ca9619c7'
  new_cat.active = 'true';
  new_cat.insert();