- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 03:10 AM
Hi All,
I have added a widget on 'ticket' page. I want to show this widget only if ritm record on portal belong to one specific item. i am trying to use below script in widget but it is not working:
Server Script
*****************************
(function() { /* populate the 'data' object */ /* e.g., data.table = $sp.getValue('table'); */
//data.table = $sp.getValue('sc_cat_item');
gs.log('input action' + input.action,'smr');
if (input && input.action === "undefined")
{
startSearch();
}
function startSearch() {
data.visible = false;
var nam = $sp.getValue('sys_id');
var grvi = new GlideRecord("sc_req_item");
grvi.addQuery("sys_id", nam);
grvi.addQuery("cat_item", "ad9cc7e41b5711904bf3b99f034bcbf2");
grvi.query();
gs.log("nam" + nam, grvi.getRowCount(), 'smr');
if (grvi.next()) {
data.visible = true;
} } })();
********************************
Client Controller
************************************
function($scope) { /* widget controller */
var c = this;
var gForm = $scope.page.g_form;
c.show = function() {
console.log('in client');
c.data.action = 'searchData';
};
}
******************************
html
**************************
<div id="root" ng-if="c.show() == true"></div>
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 03:47 AM - edited 12-12-2022 03:48 AM
You don't need client script in this case, follow below:
Server:
data.visible = false;
var nam = $sp.getValue('sys_id'); // try using var nam = $sp.getParameter('sys_id'); of URL contains sysid of RITM.
var grvi = new GlideRecord("sc_req_item");
grvi.addQuery("sys_id", nam);
grvi.addQuery("cat_item", "ad9cc7e41b5711904bf3b99f034bcbf2");
grvi.query();
gs.log("nam" + nam, grvi.getRowCount(), 'smr');
if (grvi.next()) {
data.visible = true;
}
HTML:
<div id="root" ng-if="data.visible"></div>
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 03:46 AM
@Community Alums
check this
https://www.servicenow.com/community/now-platform-forum/show-hide-widget-with-condition/m-p/1065415
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 03:47 AM - edited 12-12-2022 03:48 AM
You don't need client script in this case, follow below:
Server:
data.visible = false;
var nam = $sp.getValue('sys_id'); // try using var nam = $sp.getParameter('sys_id'); of URL contains sysid of RITM.
var grvi = new GlideRecord("sc_req_item");
grvi.addQuery("sys_id", nam);
grvi.addQuery("cat_item", "ad9cc7e41b5711904bf3b99f034bcbf2");
grvi.query();
gs.log("nam" + nam, grvi.getRowCount(), 'smr');
if (grvi.next()) {
data.visible = true;
}
HTML:
<div id="root" ng-if="data.visible"></div>
Raghav
MVP 2023