- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2020 04:56 AM
Dear Community Members,
I am working on enabling state progress bar on case form. I have managed to do it with process flow formatter.
Now, thing is I am getting all the state in the progress bar. As below:
Now my question is, is there any way I can show only certain state based on scenerio. For example, if a case is closed completed then closed incomplete and suspended should not be visible. In other case, if a case is closed incomplete, Awaiting acceptance and closed complete should not be visible.
Can I achieve this? If yes, please help me how.
Regards,
Peeyush Jaroli
Solved! Go to Solution.
- Labels:
-
HR Service Delivery

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2020 08:13 AM
Hi,
It is possible using Onchange() client script and Script include combination i have done this try below code it work.
OnChange() Client script on State Field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var gr = new GlideAjax('Test');//Test is Script include name
gr.addParam('sysparm_name', 'getDetails');//getDetails is function name in script include
gr.addParam('syaparm_val', newValue);//newValue is state value
gr.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if (answer == 'Authorize') //here set your case ie. 'closed completed' instead of Authorize
{
//here hide 'closed incomplete' and 'suspended' using g_form.removeOption() method
g_form.removeOption('state', '-5'); //here pass your 'closed incomplete' backend value instead of '-5'
g_form.removeOption('state', '-3'); //here pass your 'suspended' backend value instead of '-3'
} else if (answer == 'New') //here set your case ie. 'closed incomplete' instead of 'New'
{
//here hide 'Awaiting acceptance' and 'closed complete' g_form.removeOption() method and also do same as above pass correct backend value
g_form.removeOption("state", '-1');//set 'Awaiting acceptance' backend value instead of '-1'
g_form.removeOption("state", '-2');//set 'closed complete' backend value instead of '-2'
}
}
}
Script Include to check the state with Process flow state and it return label of that current state based on that hide state.
var Test = Class.create();
Test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var state_val = this.getParameter('syaparm_val');
gs.addInfoMessage("state=" + stateval);
var gr = new GlideRecord('sys_process_flow');
gr.addQuery('table', 'change_request');//here pass your table name instead of change_request
gr.query();
while (gr.next()) {
if (gr.condition == 'state='+state_val+'^EQ') //compare current condition with process flow condtion
{
gs.addInfoMessage("label=" + gr.label);
if (gr.label == 'Authorize')//if the label is 'closed completed' then return it to client script
{
return gr.label;
}
}
}
},
type: 'Test'
});
I hope it will help you.
Please Mark Correct/Helpful answer if it help you in any way.
Thanks and Regards,
Kunal.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2020 05:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2020 08:13 AM
Hi,
It is possible using Onchange() client script and Script include combination i have done this try below code it work.
OnChange() Client script on State Field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var gr = new GlideAjax('Test');//Test is Script include name
gr.addParam('sysparm_name', 'getDetails');//getDetails is function name in script include
gr.addParam('syaparm_val', newValue);//newValue is state value
gr.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if (answer == 'Authorize') //here set your case ie. 'closed completed' instead of Authorize
{
//here hide 'closed incomplete' and 'suspended' using g_form.removeOption() method
g_form.removeOption('state', '-5'); //here pass your 'closed incomplete' backend value instead of '-5'
g_form.removeOption('state', '-3'); //here pass your 'suspended' backend value instead of '-3'
} else if (answer == 'New') //here set your case ie. 'closed incomplete' instead of 'New'
{
//here hide 'Awaiting acceptance' and 'closed complete' g_form.removeOption() method and also do same as above pass correct backend value
g_form.removeOption("state", '-1');//set 'Awaiting acceptance' backend value instead of '-1'
g_form.removeOption("state", '-2');//set 'closed complete' backend value instead of '-2'
}
}
}
Script Include to check the state with Process flow state and it return label of that current state based on that hide state.
var Test = Class.create();
Test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var state_val = this.getParameter('syaparm_val');
gs.addInfoMessage("state=" + stateval);
var gr = new GlideRecord('sys_process_flow');
gr.addQuery('table', 'change_request');//here pass your table name instead of change_request
gr.query();
while (gr.next()) {
if (gr.condition == 'state='+state_val+'^EQ') //compare current condition with process flow condtion
{
gs.addInfoMessage("label=" + gr.label);
if (gr.label == 'Authorize')//if the label is 'closed completed' then return it to client script
{
return gr.label;
}
}
}
},
type: 'Test'
});
I hope it will help you.
Please Mark Correct/Helpful answer if it help you in any way.
Thanks and Regards,
Kunal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2020 11:56 PM
Hi Kunal,
Thanks for your response.
I have done below changes but its not working.
Scenario - I have clicked on closed complete so, Closed incomplete and Suspended should hide.
A. Script Include Name - ProcessFlow
var ProcessFlow = Class.create();
Test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var state_val = this.getParameter('syaparm_val');
gs.addInfoMessage("state=" + stateval);
var gr = new GlideRecord('sys_process_flow');
gr.addQuery('table', 'sn_hr_core_case');//here pass your table name instead of change_request
gr.query();
while (gr.next()) {
if (gr.condition == 'state='+state_val+'^EQ') //compare current condition with process flow condtion
{
gs.addInfoMessage("label=" + gr.label);
if (gr.label == 'Closed Complete')//if the label is 'closed completed' then return it to client script
{
return gr.label;
}
}
}
},
type: 'ProcessFlow'
});
B. Client Script Name: Process Flow
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var gr = new GlideAjax('ProcessFlow');//Test is Script include name
gr.addParam('sysparm_name', 'getDetails');//getDetails is function name in script include
gr.addParam('syaparm_val', newValue);//newValue is state value
gr.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if (answer == 'Closed Complete') //here set your case ie. 'closed completed' instead of Authorize
{
//here hide 'closed incomplete' and 'suspended' using g_form.removeOption() method
g_form.removeOption('state', '3'); //here pass your 'closed incomplete' backend value instead of '-5'
g_form.removeOption('state', '24'); //here pass your 'suspended' backend value instead of '-3'
} else if (answer == 'Closed Incomplete') //here set your case ie. 'closed incomplete' instead of 'New'
{
//here hide 'Awaiting acceptance' and 'closed complete' g_form.removeOption() method and also do same as above pass correct backend value
g_form.removeOption("state", '4');//set 'Awaiting acceptance' backend value instead of '-1'
g_form.removeOption("state", '3');//set 'closed complete' backend value instead of '-2'
}
}
}
Can you please tell what I am missing?
Regards,
Peeyush Jaroli

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2020 12:07 AM
Hi,
Is your control is going in Script include or Not?
OnChange() Client script should be on state field. so the newValue is your current state
Make sure that field backend name is correct.
use gs.addInfoMessage() to check that control is where.
Thanks,
Kunal