Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How to restore the knowledge articles from one instance to another

msc
Tera Contributor

Hi Everyone 

 

Need your help on one of my requirement to get the knowledge articles from one instance and create or update it on another instance through schedule job. We have to get the data ( publish , retired ) from one instance and create or update it on another instance with out any information or mail to trigger the user.

 

Thanks 

 

4 REPLIES 4

Tanushree Maiti
Tera Sage

Hi @msc 

 

you can use REST API in instance B to get KB article from instance A.

Also there is a OOB knowledge scripted rest api , you can use get method for your requirement.

 

https://<Your instancence name>/sys_ws_definition.do?sys_id=8ad394c8db03220099f93691f0b8f584&sysparm_view=&sysparm_record_target=sys_ws_definition&sysparm_record_row=1&sysparm_record_list=nameSTARTSWITHknowledge%5EORDERBYname&sysparm_record_rows=1

 

If you want to created scripted rest api for your requirement. you will get guide from there.

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Ankur Bawiskar
Tera Patron

@msc 

But why is this required?

are you doing this between 2 different ServiceNow instances i.e. between 2 different companies?

You will have to use custom scripted REST API to handle this.

also check this

How to create knowledge article in ServiceNow with article state as Publish? 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

We are doing this activity from commercial to fedramp related instances

 

ChallaR
Giga Guru

Hi @msc ,

 

you can archive with schedule  job 

Scheduled Script -
(function execute() {

  var r = new sn_ws.RESTMessageV2('KB Sync from Source', 'get');
  var response = r.execute();
  var data = JSON.parse(response.getBody()).result;

  for (var i = 0; i < data.length; i++) {

    var src=data[i];

    var kb = new GlideRecord('kb_knowledge');
    kb.addQuery('u_source_sys_id', src.sys_id); // custom field
    kb.query();

    if (kb.next()) {
      // UPDATE
      kb.setWorkflow(false); // ✅ No emails / no workflows
    } else {
      // CREATE
      kb.initialize();
      kb.setValue('u_source_sys_id', src.sys_id);
      kb.setWorkflow(false); // ✅ No emails / no workflows
    }

    kb.short_description = src.short_description;
    kb.text = src.text;
    kb.workflow_state = src.workflow_state; // published / retired

    if (kb.isNewRecord())
      kb.insert();
    else
      kb.update();

  }

})();
Add this custom field on kb_knowledge
Field name Type
u_source_sys_idString (32)

 

Please accept the solution and close the tried if this is helpful.

 

Thanks,

Rithika.ch