Capture requested for active status in new variable in a catalog item

Surendra6
Tera Contributor

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

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@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';
    }
});

 

Amit Verma
Kilo Patron
Kilo Patron

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 -

 

AmitVerma_0-1729745423464.png

AmitVerma_1-1729745439830.png

 

 

AmitVerma_3-1729745550386.png

 

AmitVerma_4-1729745563485.png

 

Output -

AmitVerma_5-1729745582616.png

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.