- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 01:45 AM
Hi all,
I'm relatively new to ServiceNow, but i have created an internal Service Portal for change requests to be processed. The problem i'm having is that the state field is showing all options available to the users, even though the client script 'Show valid state values' has been switched to run in all ui types. Can anyone tell me why its not working on the Service Portal but it is in the standard ui?
Many thanks in advanced for your help!
Service Portal:
Standard UI:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2018 07:07 AM
So I finally got this working, and thank you to Michael for your help.
I created a new onLoad client script that removes the unwanted states.
Make sure to set the UI Type to Mobile / Service Portal
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('state') == '-5')// For state use your database value and same for other states
{
g_form.removeOption('state', '-3');
g_form.removeOption('state', '-2');
g_form.removeOption('state', '-1');
g_form.removeOption('state', '0');
g_form.removeOption('state', '3');
g_form.removeOption('state', '4');
}
}
repeat as necessary through all the state values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 05:58 AM
Can you post the code 'Show valid state values'?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 07:16 AM
Hi,
Thanks for your reply.
Yes ofcourse, the code is below, it is a client script on the Change_request table out of the box.
function onLoad() {
var ga = new GlideAjax('ChangeRequestStateHandlerAjax');
ga.addParam('sysparm_name','ajaxFunction_getNextStateValues');
ga.addParam('sysparm_change_sys_id',g_form.getUniqueValue());
ga.addParam('sysparm_change_type',g_form.getValue('type'));
ga.getXMLAnswer(nextValidValue);
}
function nextValidValue(nextStateValues) {
var validStates = [];
var returnedStates = nextStateValues.evalJSON();
var originalValues = {};
originalValues[g_form.getValue('state')] = g_form.getOption('state',g_form.getValue('state')).innerHTML;
validStates.push(originalValues);
for (var i = 0; i < returnedStates.length; i++) {
for (var j = 0; j < g_form.getControl('state').length; j++) {
if (returnedStates[i] == g_form.getControl('state')[j].value) {
var keyVal = {};
keyVal[returnedStates[i]] = g_form.getControl('state')[j].innerHTML;
validStates.push(keyVal);
break;
}
}
}
g_form.clearOptions('state');
for (var i = 0; i < validStates.length; i++) {
var currState = validStates[i];
for (key in currState)
g_form.addOption('state', key, currState[key]);
}
if (g_form.getValue("on_hold") === 'true') {
g_form.showFieldMsg("state", getMessage("Change is currently on hold"));
return;
}
if (g_form.getValue('state') == "-4" || g_form.getValue('state') == "-3" )
g_form.showFieldMsg("state", getMessage("Change is waiting for approval"));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2017 06:52 AM
Can anybody help with this one? Still stuck unfortunately.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 04:07 AM
I still have this question. I found Restrict values of a choice field based on its current status, which eludes to the same problem i'm having. Michael.Fry, you speak about this field in the post. Any way in which we can get it to work on the Service Portal? I'm really new to this.
Many thanks
Luke