
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2017 07:16 AM
I would like to automatically attach a knowledge article to a change request based off of the Configuration Item. Each CI would have a specific article that would be attached to each change request for that CI. I would like the article to be attached either at creation or when submitted via a UI Action, but I'm open to better suggestions. The end goal would be to have documented instructions attached to the ticket when the change is made.
Thank you in advance for any help you can provide!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2017 03:12 PM
I was able to figure out how to accomplish this, from viewing several different community posts, so thank you to everyone who is active in the community!
I'll need to clean up the code to work in a real world environment but this is the basics (I did this from a client script, on load)...
To insert a hyperlink:
- I created a url field on the change request form called u_knowledge_article'
- I used the deployment type field to determine which article to input:
if(g_form.getValue('u_deployment_type') == 'Data Fix') {
g_form.setValue('u_knowledge_article','https://[your instance].service-now.com/kb_view.do?sysparm_article=KB0000003');
- You'll probably want to add an if to make sure the field isn't already populated
To insert the article text:
- I created an html field on the change request form called u_test_html_field
- I wrote this script to pull in the text field from the knowledge article I wanted
if(g_form.getValue('u_test_html_field') == ''){ //check if the field is already populated
var target = new GlideRecord('kb_knowledge');
target.addQuery('sys_id', '3b0fccee0a0a0b9b00d34b36ea41a43e'); //sys id of the article
target.query();
while(target.next()){
var info = target.text;
g_form.setValue('u_test_html_field',info);
}
}
- I'll most likely use this solution in my scenario, it will be nice to get the what the instructions were at the time of the change request.
- I'm really hoping ServiceNow get's versioning in soon, then you could link to the version.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2017 03:12 PM
I was able to figure out how to accomplish this, from viewing several different community posts, so thank you to everyone who is active in the community!
I'll need to clean up the code to work in a real world environment but this is the basics (I did this from a client script, on load)...
To insert a hyperlink:
- I created a url field on the change request form called u_knowledge_article'
- I used the deployment type field to determine which article to input:
if(g_form.getValue('u_deployment_type') == 'Data Fix') {
g_form.setValue('u_knowledge_article','https://[your instance].service-now.com/kb_view.do?sysparm_article=KB0000003');
- You'll probably want to add an if to make sure the field isn't already populated
To insert the article text:
- I created an html field on the change request form called u_test_html_field
- I wrote this script to pull in the text field from the knowledge article I wanted
if(g_form.getValue('u_test_html_field') == ''){ //check if the field is already populated
var target = new GlideRecord('kb_knowledge');
target.addQuery('sys_id', '3b0fccee0a0a0b9b00d34b36ea41a43e'); //sys id of the article
target.query();
while(target.next()){
var info = target.text;
g_form.setValue('u_test_html_field',info);
}
}
- I'll most likely use this solution in my scenario, it will be nice to get the what the instructions were at the time of the change request.
- I'm really hoping ServiceNow get's versioning in soon, then you could link to the version.