knowledge management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2025 02:18 AM
As a content creator I want to migrate confluence documents. Is there an integration tool available? How can we convert anything from confluence that cannot be exported to word.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2025 07:05 AM
There is no OOB way to convert Confluence to SN knowledge. You could check for store apps, but what I saw, most of them are related to searching confluence through ServiceNow.
Some links you could look at:
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 03:32 PM - edited 03-24-2025 03:39 PM
Hello @developerguryu
Pre-requisites:
1. It is important to understand the scope of work which is retrieve (GET) Confluence articles into ServiceNow and/or create/update Confluence articles from ServiceNow (POST/PUT).
2. Let's assume the scope of work is to Retrieve Confluence Articles and then create a KB article into ServiceNow of it.
3. I would recommend having some practice in a free confluence cloud trial (with your personal e-mail) as well as in ServiceNow PDI.
Development Steps:
1. Login to Confluence cloud and create token for Basic Authorization as shown below:
2. In ServiceNow, Navigate to System Definition > Tables and open Table Name: sys_auth_profile_basic (sys_auth_profile_basic.LIST) and then ensure the Column label "Password" Max length is increased to a higher value than your API token
3. Navigate to System Web Services > Outbound > REST Message and create one as shown below:
You can select Authentication type Basic and create Basic auth profile from here which will have a name: confluence, username as your e-mail and password as the API Token copied from step#1 above.
Taken reference from this ServiceNow post to identify the confluence rest API End points: https://www.servicenow.com/community/itsm-forum/import-knowledge-articles-from-confluence-using-inte...
4. The HTTP method "GET" with name "Default GET" created automatically can be modified as shown below:
Under Related Links, click Auto-generate variables and enter the value for the variable
5. How to get the confluence ID for the page:
Open Confluence page and click three dots (More Actions) on the top right corner and then Advanced Details > Content Information can give the pageId.
Similarly, you can get:
Space Keys with /wiki/rest/api/space?limit=99999
All Articles within a space /wiki/rest/api/content?spaceKey=TEST
6. Under Related Links, click Test and you should see the 200 server response with the JSON payload.
7. Under Related Links, click Preview Script Usage, copy paste this code in Scripts - Background to print the responseBody as:
gs.info(responseBody);
8. Now, you need to modify this code to create and publish a KB Article in ServiceNow from this confluence article JSON response
NOTE: If you find out that there is a hyperlink in your confluence article which is trimmed in the JSON response then you can use the. replace function as shown in the below code:
Prerequisites here:
- Get the Instant Publish Workflow sys_id and then create a system property of it as it is not recommended to use sys_id in the code. Table Name: wf_workflow.LIST
Table: sys_properties
NOTE: Always recommened to have roles associated with the system property.
Workflow: Instant Publish --> This workflow out of the box needs workflow field value to be Draft and scheduled_publish_date field must be at least 24 hr after the current date publish the article:
NOTE: I modified this workflow to instantly publish, so removed the timer activity:
Click Workflow Actions (three horizontal lines left to the Workflow name > Check out), click X on the activity and then Click Publish in the Workflow Actions.
Here is the background script which can be your fix script which can be scheduled once in a day or so:
try {
var r = new sn_ws.RESTMessageV2('Confluence', 'Default GET');
r.setStringParameterNoEscape('confluenceID', '327681');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var jsonResponseBody = JSON.parse(responseBody);
// Extract HTML content from the response
var htmlContent = jsonResponseBody.body.export_view.value;
// Modify the href links in the HTML content to include target="_blank" for opening in a new tab
var modifiedHtmlContent = htmlContent.replace(/<a\s+href=["'][^"']*(\/wiki[^"']*)["']/gi, function(match, url) {
return '<a href="https://usert8869.atlassian.net' + url + '" target="_blank"';
});
// Create a new knowledge article record
var kbArticle = new GlideRecord('kb_knowledge');
kbArticle.initialize(); // Initialize the new record
kbArticle.setDisplayValue('kb_knowledge_base', 'Knowledge'); // Set Knowledge base here
kbArticle.short_description = jsonResponseBody.title;
kbArticle.text = modifiedHtmlContent; // Set the modified HTML content to the text field which will be article body
kbArticle.workflow_state = 'draft';
kbArticle.setWorkflow(false); // stop any other server side logic on the 'kb_knowledge table'
kbArticle.insert(); // new knowledge article into the 'kb_knowledge' table
kbArticle.setWorkflow(true); // enabled other server side logic on the 'kb_knowledge table'
gs.print(kbArticle.number + " created successfully");
// Calling workflow from sys_property to instant publish the newly created article
var workflow = new Workflow();
var workflowSysID = gs.getProperty('article.instant.publish'); // calling the system property of Instant Publish workflow instead of it's sys_id
workflow.startFlow(workflowSysID, kbArticle, 'update'); // Calling the Instant Publish flow to publish the article. You can comment this line if it is not required.
} catch (ex) {
var message = ex.message;
gs.error("Error occurred: " + message);
}
Result:
You can further modify your code to check for duplicates or for updated Confluence content in the JSON response using if and else loop conditions..
Hope that helps!