Capture requested for active status in new variable in a catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 08:03 PM
Hi All,
We have a requirement that create a new variable and capture the true or false accordingly in that variable based on the requested for's active status in a catalog form.
Could you please provide a onChange client script for this.
Thanks,
Surendra

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 08:10 PM
@Surendra6 You need to create an onChange client script and a script include to achieve this as follows.
onChange client script on the requested for field.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Fetch the requested_for's active status when the field changes
checkUserActiveStatus(newValue);
}
function checkUserActiveStatus(userId) {
var ga = new GlideAjax('UserActiveStatus'); // Custom Script Include
ga.addParam('sysparm_name', 'checkActive');
ga.addParam('sysparm_user_id', userId);
ga.getXMLAnswer(function(response) {
var isActive = response;
g_form.setValue('user_active_status', isActive); // Set the hidden variable with true/false
});
}
Here is the client callable script include.
var UserActiveStatus = Class.create();
UserActiveStatus.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkActive: function() {
var userId = this.getParameter('sysparm_user_id');
var userGR = new GlideRecord('sys_user');
if (userGR.get(userId)) {
return userGR.active.toString(); // Return 'true' or 'false'
}
return 'false';
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 09:53 PM
Hi @Surendra6
I assume that Requested For field is a reference field in your catalog item. If yes, you can make use of Auto-Populate feature to populate requestor active status. Refer below snips -
Output -
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.