Adding Sys_KB_ID to a URL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2020 08:53 AM
Hello -
I'm new to this so please forgive what may seem like a simple question. I am having a hard time figuring out how to get the sys_kb_id parameter added to a URL from my Search Sources for the OOB "search" page.
OOB this works:
<div>
<a href="?id=kb_article&sys_id={{item.sys_id}}&table={{item.table}}" class="h4 text-primary m-b-sm block">
<span ng-bind-html="highlight(item.primary, data.q)"></span>
</a>
<span class="text-muted" ng-repeat="f in item.fields">
<span class="m-l-xs m-r-xs" ng-if="!$first"> · </span>
{{f.label}}: <span ng-bind-html="highlight(f.display_value, data.q)"></span>
</span>
</div>
BUT I have a custom page that is called "developer_member_information" and this page needs to the Sys_KB_ID in order to display the knowledge article correctly. I tried to change the HTML to this but it doesn't work.
<div>
<a href="?id=developer_member_information&sys_kb_id={{$sp.getParameter('sys_kb_id')}}" class="h4 text-primary m-b-sm block">
<span ng-bind-html="highlight(item.primary, data.q)"></span>
</a>
<span class="text-muted" ng-repeat="f in item.fields">
<span class="m-l-xs m-r-xs" ng-if="!$first"> · </span>
{{f.label}}: <span ng-bind-html="highlight(f.display_value, data.q)"></span>
</span>
</div>
I also tried this...
<div>
<a href="?id=developer_member_information&sys_kb_id={{item.sys_kb_id}}&table={{item.table}} class="h4 text-primary m-b-sm block">
<span ng-bind-html="highlight(item.primary, data.q)"></span>
</a>
<span class="text-muted" ng-repeat="f in item.fields">
<span class="m-l-xs m-r-xs" ng-if="!$first"> · </span>
{{f.label}}: <span ng-bind-html="highlight(f.display_value, data.q)"></span>
</span>
</div>
I've also tried to add a script function to get the sys_kb_id from some other scripts we have but it always just gives me a blank Sys_KB_ID in the URL.Like this...
If anyone has any simple tricks for me, I'd appreciate it.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2020 09:52 AM
Hi
Your serach source is defined on a data source, which usually is pointed to a Servicenow table. The "item" variable used in the search source contains that record that you've clicked on on the search result that came up after searching that data source (i.e that table).
Now, if that table record sys_id is the id you want to pass to your parameter, then you can replace your anchor tag in the search source template with the snippet below:
<a href="?id=developer_member_information&sys_kb_id={{item.sys_id}}&table={{item.table}} class="h4 text-primary m-b-sm block">
Else, if it's not the sys_id of the data source table, then you can do a dot-walk to the relationship table field that your "developer_member_information" page expects in the "sys_kb_id" parameter, something like:
<a href="?id=developer_member_information&sys_kb_id={{item.<kb_article.sys_id>.toString()}}&table={{item.table}} class="h4 text-primary m-b-sm block">
You'd need to replace the highlighted value with the dot-walked relationship form the data source table to get the sys_id of the record that needs to be passed as the parameter value.
Thanks & Regards,
Rishabh Jha
Aavenir (https://www.aavenir.com/)