- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 10:39 AM
based on taxonmy topic , created record producer field in widget shows dropdown names
Below i written server script, how to fetch topic_id from portal url(esc?id=emp_taxonomy_topic&topic_id=77b83e4cc3203010069aec4b7d40dd54) and replace it in below code of topic=0ce0fe08c3203010069aec4b7d40ddde
i tried pass gc.addQuery('catalog_item', $sp.getParameter("topic_id") ); but this not working well
server script
(function() {
data.catalog_items=[];
var grRP=new GlideRecord('m2m_connected_content');
grRP.addEncodedQuery("catalog_item.sys_class_name=sc_cat_item_producer^topic=0ce0fe08c3203010069aec4b7d40ddde");
//grRP.addEncodedQuery("catalog_item.sys_class_name=sc_cat_item_producer");
grRP.query();
while(grRP.next())
{
var inc;
inc=grRP.getValue('catalog_item');
data.catalog_items.push(inc);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 11:19 AM - edited 10-20-2023 11:20 AM
Hi @Bhavani3, do you want to search items based on the topic, right?
You can enable AI Search for your instance.
Go to AI Search > AI Search Status
Enable AI Search
If you have a Utah instance, your employee center will have a search on the topic page
This is an Out Of The Box functionality
If my answer helped you, please mark my answer as helpful.
Vanderlei Catione Junior | LinkedIn
Senior ServicePortal Developer / TechLead at The Cloud People
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 06:41 AM
Hi @Bhavani3, If you really need to create a custom widget(I don't recommend because ServiceNow support only OOTB features ), you can try this
Server Script:
data.options = []
var grOptions = new GlideRecordSecure();
grOptions.addEncodedQuery();
grOptions.query()
while(grOptions.next()){
data.options.push({
name: grOptions.getDisplayValue(""),
id: grOptions.getValue("")
})
}
<select name="producers" id="producers-select" ng-change="c.redirect()" ng-bind="c.recordProducer">
<option value="{{option.id}}" ng-repeat="option in data.options">{{option.name}}</option>
</select>
Client
c.redirect = function(){
window.open("?id=sc_cat_item&id="+c.recordProducer)//replace the id for your Catalog item Page
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 10:52 AM
Is topic id a catalog item? - gc.addQuery('catalog_item', $sp.getParameter("topic_id") );
Can you also print the value of the topic id as gs.info('$sp.getParameter("topic_id") -- '+$sp.getParameter("topic_id")).
This way we know if you are getting the right value
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 10:58 AM - edited 10-19-2023 10:58 AM
Hi, @Bhavani3 try this code
(function() {
data.catalog_items=[];
var topic = $sp.getParameter("topic_id")
var grRP=new GlideRecord('m2m_connected_content');
grRP.addEncodedQuery("topic="+topic+"^content_type=98f9a16553622010069addeeff7b1248^catalog_item.sys_class_name=sc_cat_item_producer^ORDERBYorder");
grRP.query();
while(grRP.next())
{
var inc;
inc=grRP.getValue('catalog_item');
data.catalog_items.push(inc);
}
But I still have some doubts
Where is this code used?
What is his objective?
If my answer helped you, please mark my answer as helpful.
Vanderlei Catione Junior | LinkedIn
Senior ServicePortal Developer / TechLead at The Cloud People
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 11:26 AM
Hi @Vanderlei
I created widget for in html i creted field name "record producer " drop down values and it placed in portal page .By connected connect table(m2m_connected_content)i get the mapping between record producer and topic .
In portal Based on topic_id url(esc?id=emp_taxonomy_topic&topic_id=77b83e4cc3203010069aec4b7d40dd54) ,need to display record producer names in widget and if we click record producer name then redirect record producer form in portal.
in below snapchat,based on topic this catalog item displayed in widget
HTML code
<div class="record" aria-hidden="true" ng-model="name">
Select Record Producer:<sn-record-picker
id="name"
field="name"
table="'sc_cat_item_producer'"
display-field="'name'"
value-field="'sys_id'"
search-fields="'name'"
page-size="100">
</sn-record-picker>
</div>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 04:14 PM
Hi @Bhavani3, try this
<div class="record" aria-hidden="true" ng-model="name">
Select Record Producer:
<sn-record-picker field="name"
table="'sc_cat_item_producer'"
display-field="'name'"
value-field="'sys_id'"
search-fields="'name'"
default-query="'taxonomy_topic={{c.your_sys_id}}'"
page-size="100"
></sn-record-picker>
</div>