How to add instance specific Knowledge article URLs in Servicenow Widgets.

Rajyalakshmi
Tera Contributor

Hi ,

 

we have requiremnet ,in the widget we need to show knowledge article URL ,it shold open instance specific console view of the article.

 

Please help how we can write this validation in the Widget code.

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Rajyalakshmi 

standard console view for a knowledge article looks like:

https://<INSTANCE>.service-now.com/x/now/knowledge/article/<ARTICLE_SYS_ID>
Replace <INSTANCE> with the dynamic instance URL, and <ARTICLE_SYS_ID> with your article’s sys_id value.

Server Script Example (for Widget):

(function() {
var sysId = input.articleSysId; // Pass this from your widget options/params or GlideRecord
data.instanceUrl = gs.getProperty('glide.servlet.uri');
data.articleUrl = data.instanceUrl + 'x/now/knowledge/article/' + sysId;
})();

HTML

<div>
  <a ng-href="{{data.articleUrl}}" target="_blank">
    View Knowledge Article
  </a>
</div>

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

@Rajyalakshmi 

even I don't have that property but it will give you the instance URL

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Rajyalakshmi 

standard console view for a knowledge article looks like:

https://<INSTANCE>.service-now.com/x/now/knowledge/article/<ARTICLE_SYS_ID>
Replace <INSTANCE> with the dynamic instance URL, and <ARTICLE_SYS_ID> with your article’s sys_id value.

Server Script Example (for Widget):

(function() {
var sysId = input.articleSysId; // Pass this from your widget options/params or GlideRecord
data.instanceUrl = gs.getProperty('glide.servlet.uri');
data.articleUrl = data.instanceUrl + 'x/now/knowledge/article/' + sysId;
})();

HTML

<div>
  <a ng-href="{{data.articleUrl}}" target="_blank">
    View Knowledge Article
  </a>
</div>

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar ,

 

Thank you for the update.In my instance we don't have glide.servlet.uri system property. We have instance_name ,value is  xyzdev .Please help with this,how the server code need to be write for this ?

@Rajyalakshmi 

even I don't have that property but it will give you the instance URL

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

SupriyaWaghmode
Kilo Sage

Hello @Rajyalakshmi ,

 

Custom widget for link generation-

In a custom widget, you can dynamically generate the URL for a knowledge article. The typical Service Portal

URL for a knowledge article is in the format:

 

https://<instance_name>.service-now.com/sp?id=kb_article&sys_id=<sys_id_of_article>

 

Also check the below link 

https://www.servicenow.com/community/developer-forum/knowledge-article-dynamic-linking/m-p/1434007

 

Thanks & Regards,

Supriya Waghmode |ServiceNow Consultant