Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

rest integration with Active directory

solanovale
Tera Contributor

I am trying to create a catalog item which creates a task where the user is assigned to the ad group requested automatically.  How can I achieve that automation? 

 

I created the following action:

(function execute(inputs, outputs) {
    try {
        // Name of group that needs to be added
        var group = 'SOCURE_SSO_ACCESS_GROUP';
        var rest, domain, environment;

        // Determine environment
        if (gs.getProperty('instance_name') == 'tradestationdev') {
            rest = 'ADGroupMembership_PROD';
            domain = 'trad';
            environment = 'prod';
        } else {
            rest = 'ADGroupMembership_ENG';
            domain = 'qa';
            environment = 'qa';
        }

        var action = inputs.select_action_type;      
        var userSysId = inputs.action_requested_for;  

        // Get user record
        var user = new GlideRecord('sys_user');
        if (!user.get(userSysId)) {
            throw 'User not found: ' + userSysId;
        }

        // Call REST message
        var message = new sn_ws.RESTMessageV2(rest, action);
        message.setStringParameterNoEscape('user', user.getValue('user_name'));
        message.setStringParameterNoEscape('group', group);
        message.setStringParameterNoEscape('domain', domain);
        message.setStringParameterNoEscape('environment', environment);

        var r = message.execute();
        var status = r.getStatusCode();

        if (status == 202) {
            var body = r.getBody();
            var parsed = JSON.parse(body);
            outputs.job_id = parsed.job_id; // pass to next Flow step
        }

        outputs.result = status;

    } catch (e) {
        // In case of any error, still assign outputs
        outputs.result = -1;
        outputs.job_id = '';
        outputs.error_message = e.toString();
    }
})(inputs, outputs);

solanovale_0-1764876473467.png

solanovale_1-1764876503899.pngsolanovale_2-1764876540015.png

solanovale_3-1764876667742.png

 

 

I want it now to check if that was successful, if so leave a worknote on the sctack and close it if note leave a worknote on the sctask informing the integration failed. 

 

This is how my flow looks so far:

solanovale_4-1764876719346.png

solanovale_5-1764876746221.png

Would appreciate it if someone can provide guidance

0 REPLIES 0