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.

Enable AD Activity and Password Reset AD activity showing error?

siva44
Tera Contributor

I am created the workflow for AD integration and I have mapped AD attributes through run script but account is successfully created but that is locked in AD and also getting errors below situvations

case1:  

 workflow activites order  

    >> Create AD ---enable AD account  in this case I am getting the error in enable ad activity  like below

error: 

   The server is unwilling to process the request.

HRESULT: [-2147016651]

Stack Trace: at System.DirectoryServices.DirectoryEntry.CommitChanges()
at CommitChanges(Object , Object[] )
at System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(Object target, Object[] arguments, MethodInformation methodInformation, Object[] originalArguments)

 

case2:  

 workflow activites order  

    >> Create AD ---Reset Ad passowrd---enable AD account  in this case I am getting the error  in reset AD activity like below

 

error:

The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
HRESULT: [-2147023174]

 

 

run script:

generateScratchpad();

function generateScratchpad() {
    //Get First, Middle, Last name fields.  Make sure they are String Fields
    var first = current.variables.first_name.toString();
    var last = current.variables.last_name.toString();
    //create userID  
    var ID = first+'.'+last;
//Set the scratchpad for all needed items.
    workflow.scratchpad.dN = current.variables.first_name + " " + current.variables.last_name;  //Display Name (first, last)
    workflow.scratchpad.first = current.variables.first_name;  //First Name
    workflow.scratchpad.last = current.variables.last_name;  // Last Name

    workflow.scratchpad.phone = current.variables.business_phone;  //phone
    workflow.scratchpad.email = current.variables.shared_mailbox;  //email Address
    workflow.scratchpad.id = ID;


    function generateRandomPassword(length) {
        var charset = "abcdefghijnopqrstuvwxyzABCDEFGHIJNOPQRSTUVWXYZ0123456789!@#$%^&*()_-+=<>?";
        var password = "";
        for (var i = 0; i < length; i++) {
            var randomIndex = Math.floor(Math.random() * charset.length);
            password += charset[randomIndex];
        }
        return password;
    }
 
    // Set the password length (default is 10, but can be customized)
    var passwordLength = 15; // Change this to your desired length
    var generatedPassword1 = generateRandomPassword(passwordLength);
  var enc = new PasswordResetUtil();
   var encrString1=enc.encryptWithKMFModule( generatedPassword1);
   workflow.scratchpad.password = var generatedPassword1;
var decrString =workflow.scratchpad.clearpass= enc.decryptWithKMFModule(encrString1);
    //Needs to start with a {
        var object = "{ ";
           
            //set the First name in AD
            object += '"givenName" : "' + workflow.scratchpad.first + '" , ';
            //set the user password in AD.
            object += '"userPassword" : "' +generatedPassword1+ '" , ';
           
            //set the last name in AD
            object += '"sn" : "' + workflow.scratchpad.last + '" , ';
           
            //set the display name in AD
            object += '"displayName" : "' + workflow.scratchpad.dN + '" , ';
           
            //if Email is not Blank, set the Email in AD
            //email may not be mandatory, and we dont want to send anything if the email is not filled in.
            if(!current.variables.shared_mailbox.nil()){
                object += '"mail" : "' + workflow.scratchpad.email + '" , ';
            }
           
            //set the login id and the domain in AD.
            object += '"userPrincipalName" : "' + ID + '" , ';
           
           
            if(current.variables.business_phone != ""){
                object += '"telephoneNumber" : "' + workflow.scratchpad.phone + '" , ';
            }
           
           
            //end the object with a }
            object += "}";
            /****************************************************************************************/
            /****************************************************************************************/
            /****************************************************************************************/
           
            //for Information purposed and possible troubleshooting, add the whole object string to the work_notes field
            current.work_notes = object+"\n"+"generatepassword:"+clearString+ "\n" +"encryptedpassword:"+encrString1+ "\n"+"decryptpassword:"+decrString;
           
           
            //Set the object to the scratchpad.
            workflow.scratchpad.object = object;
        }



0 REPLIES 0