write client script to achieve below requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 03:55 AM
Hi All,
I need to write client script for below requirement.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 10:48 AM
Does your updated code look just like this?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) return;
if (parseInt(newValue) === 7) { // 7 = Retired in your instance
var ga = new GlideAjax('CheckFSGroupMembership');
ga.addParam('sysparm_name', 'isUserInFSGroup');
ga.getXMLAnswer(function(answer) {
if (answer === 'true') {
g_form.addOption('substate', 'pending_disposal', 'Pending Disposal');
} else {
g_form.removeOption('substate', 'pending_disposal');
}
});
} else {
g_form.removeOption('substate', 'pending_disposal');
}
}
If so, can you tell how far it's getting? Or is it failing for one particular scenario?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 11:34 AM
It is not showing substate pending disposal choice on selection of state retired only the script I am using with console and alert it is giving expected output, but after removing that the pending disposal choice is not showing in substate field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 05:09 AM
The Substate field's internal name is "substatus". You need to change that in your code. Sorry I didn't catch that at first.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 05:47 AM
Please try with Below script:
Script include:
var CheckFSGroupMembership = Class.create();
CheckFSGroupMembership.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isUserInFSGroup: function() {
var userID = gs.getUserID();
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userID);
gr.query();
while (gr.next()) {
var group = gr.group.getRefRecord();
if (group && group.name.toString().startsWith('FS')) {
return 'true';
}
}
return 'false';
}
});
onLoad Client Script (fetch FS group status)
// Type: onLoad
(function() {
var ga = new GlideAjax('CheckFSGroupMembership');
ga.addParam('sysparm_name', 'isUserInFSGroup');
ga.getXMLAnswer(function(answer) {
g_scratchpad.isInFSGroup = answer === 'true';
// Initial check in case state is already 'Retired'
var state = g_form.getValue('state');
if (parseInt(state) === 7) {
updateSubstateOption(true, g_scratchpad.isInFSGroup);
}
});
function updateSubstateOption(isRetired, isInFSGroup) {
if (isRetired && isInFSGroup) {
g_form.addOption('substate', 'pending_disposal', 'Pending Disposal');
} else {
g_form.removeOption('substate', 'pending_disposal');
}
}
})();
onChange Client Script on State field
// Type: onChange
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) return;
var isRetired = parseInt(newValue) === 7;
var isInFSGroup = g_scratchpad.isInFSGroup;
// If FS Group check is still loading, wait briefly and retry
if (typeof isInFSGroup === 'undefined') {
setTimeout(function() {
isInFSGroup = g_scratchpad.isInFSGroup;
updateSubstateOption(isRetired, isInFSGroup);
}, 300); // Delay slightly to allow onLoad GlideAjax to complete
} else {
updateSubstateOption(isRetired, isInFSGroup);
}
function updateSubstateOption(isRetired, isInFSGroup) {
if (isRetired && isInFSGroup) {
g_form.addOption('substate', 'pending_disposal', 'Pending Disposal');
} else {
g_form.removeOption('substate', 'pending_disposal');
}
}
}
Please mark correct/helpful if this helps you.