
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2019 10:37 AM
We are in New York and I've had a request to create a hyperlink in an article to a selected configuration item using business rules. See red box below
Field is populated by selecting a CI from a reference field (cmdb_ci) in the knowledge form and a business rule runs to update the published article value.
I'm not sure how to obtain the CI location and create the hyperlink. Thanks in advance for any help.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2019 02:26 PM
Thanks one last question, if you wanted to specify not just a CMDB record but which view of that record to open is there a way to add on to the code to specify the view?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2019 10:48 AM
Hi,
you can create your Business Rule and use something like that in your script:
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('name','CI_name'); // i.e. 'ACBS'
gr.query();
if(gr.next())
{
var hyperlink = 'https://instance_name.service-now.com/nav_to.do?uri=cmdb_ci.do?sys_id=' + gr.sys_id; // put your instance name
gs.print(hyperlink);
}
This script will generate the URL of the CI and you can use it in your KB article.
Hope this can help you!
If I have answered your question, please mark my response as correct and/or helpful.
Thank you very much
Cheers
Alberto

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2019 12:16 PM
I understand the code but not how to integrate it with my existing business rule. I really appreciate your patience
Here is the code so far:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('cmdb_ci');
gr.addQuery(current.cmdb_ci.getName(),'CI_name'); // i.e. 'ACBS'
gr.query();
if(gr.next())
{
var hyperlink = 'https://our url/nav_to.do?uri=cmdb_ci.do?sys_id=' + gr.sys_id; // put your instance name
gs.addErrorMessage(hyperlink);
}
var cin = current.u_ciname.getDisplayValue();
var civ = current.u_civersion.getDisplayValue();
var civv = current.u_civendor.getDisplayValue();
var cio = current.u_ciowner.getDisplayValue();
var ciiao = current.u_ciitowner.getDisplayValue();
var lnbrk = "\n";
var cind = "<h4><a href="+hyperlink+">"+cin+"</a></h4>";
if(civ != ""){
var civd = "<b>Version:</b> " + civ + "<br>";
}
if(civv != ""){
var civvd = "<b>Vendor:</b> " + civv + "<br>";
}
if(cio != ""){
var ciod = "<b>Owner:</b> " + cio + "<br>";
}
if(ciiao != ""){
var ciiaod = "<b>IT Application Owner:</b> " + ciiao + "<br>";
}
current.u_kb_tb_ci_name.setValue(cind+civd + civvd+ ciod+ ciiaod);
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2019 02:00 PM
I'm having trouble getting this to work.
My message gives me sys Id of 00000b48db563f40dd2ae536ca961940 but when I click the hyperlink it says undefined.
I looked at actual item sys ID and it says this: sys_id=47b172c0db8a970016836e25ca961996
What am I doing wrong?
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('cmdb_ci');
gr.addQuery(current.cmdb_ci.getDisplayValue(),'CI_name'); // i.e. 'ACBS'
gr.query();
if(gr.next())
{
var hyperlink = 'https://our url/nav_to.do?uri=cmdb_ci.do?sys_id=' + gr.sys_id; // put your instance name
gs.addErrorMessage(hyperlink);
}
var cin = current.u_ciname.getDisplayValue();
var civ = current.u_civersion.getDisplayValue();
var civv = current.u_civendor.getDisplayValue();
var cio = current.u_ciowner.getDisplayValue();
var ciiao = current.u_ciitowner.getDisplayValue();
var lnbrk = "\n";
var cind = "<h4><a href="+hyperlink+">"+cin+"</a></h4>";
if(civ != ""){
var civd = "<b>Version:</b> " + civ + "<br>";
}
if(civv != ""){
var civvd = "<b>Vendor:</b> " + civv + "<br>";
}
if(cio != ""){
var ciod = "<b>Owner:</b> " + cio + "<br>";
}
if(ciiao != ""){
var ciiaod = "<b>IT Application Owner:</b> " + ciiao + "<br>";
}
current.u_kb_tb_ci_name.setValue(cind+civd + civvd+ ciod+ ciiaod);
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2019 02:08 PM
While building the CI field, you can do
(function executeRule(current, previous /*null when async*/) {
var ciurl = gs.getProperty('glide.servlet.uri')+'cmdb_ci.do?sys_id='+current.getValue('u_ciname');
var cin = '<a href='+ciurl+'>'+current.u_ciname.getDisplayValue()+'</a>';
var civ = current.u_civersion.getDisplayValue();
var civv = current.u_civendor.getDisplayValue();
var cio = current.u_ciowner.getDisplayValue();
var ciiao = current.u_ciitowner.getDisplayValue();
var lnbrk = "\n";
var cind = "<h4>"+cin+"</h4>";
if(civ != ""){
var civd = "<b>Version:</b> " + civ + "<br>";
}
if(civv != ""){
var civvd = "<b>Vendor:</b> " + civv + "<br>";
}
if(cio != ""){
var ciod = "<b>Owner:</b> " + cio + "<br>";
}
if(ciiao != ""){
var ciiaod = "<b>IT Application Owner:</b> " + ciiao + "<br>";
}
current.u_kb_tb_ci_name.setValue(cind+civd + civvd+ ciod+ ciiaod);
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.