
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2017 01:04 AM
We are developing a widget that we will add to the ticket page on Service Portal and we need to check using client script the value of State for example. We've tried calling gr.state and c.data.state (with matching data.state = gr.state on server side) but it is not working.
Sample part of code on client script:
if (c.data.state == 6 && c.data.active == true){
//code here
}
The counterpart on the server script:
data.active = gr.active;
data.state = gr.state;
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2017 10:42 AM
I figured it out finally! I just need to added .toString() on the gr.active and gr.state part of the server script. Then on the client script, you need to enclose the values of the fields with apostrophes since they are now strings. See the working code below:
WORKING CLIENT SCRIPT:
function($uibModal, $scope) {
var c = this;
var state = c.data.state;
var active = c.data.active;
if (state == '6' && active == 'true'){
// Code to open a modal window here
}
if (state != '6' && state != '7' && active == 'true'){
// Code to open a modal window here
}
}
WORKING SERVER SCRIPT:
(function() {
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid()) return;
// Valid sys_id
if (!gr.get(data.sys_id)) return;
// Check
if(data.table == 'incident' && gr.active == true && gr.state == 6 && gr.caller_id == gs.getUserID()){
data.state = gr.state.toString();
data.active = gr.active.toString();
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2017 10:42 AM
I figured it out finally! I just need to added .toString() on the gr.active and gr.state part of the server script. Then on the client script, you need to enclose the values of the fields with apostrophes since they are now strings. See the working code below:
WORKING CLIENT SCRIPT:
function($uibModal, $scope) {
var c = this;
var state = c.data.state;
var active = c.data.active;
if (state == '6' && active == 'true'){
// Code to open a modal window here
}
if (state != '6' && state != '7' && active == 'true'){
// Code to open a modal window here
}
}
WORKING SERVER SCRIPT:
(function() {
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid()) return;
// Valid sys_id
if (!gr.get(data.sys_id)) return;
// Check
if(data.table == 'incident' && gr.active == true && gr.state == 6 && gr.caller_id == gs.getUserID()){
data.state = gr.state.toString();
data.active = gr.active.toString();
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2017 02:59 PM
or you could just change the client script from == '7' to == 7

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2017 06:21 PM
Hi, we already did that as you can see on our original code and it did not work.