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.

Setting password in user profile through Run Script

anirban300
Kilo Guru

I am going to my profile and setting the password as "password" then when I am viewing my xml then the password is shown as "$s$kq6j5hcn7xyo4xPygKRZZHt3HSBVoCzOi9vEI43c05Y=$ZC3uHQbZGeKWaWr+3aMs59+0KzAhlfY0eS3KS03Ongw="

Now suppose I am setting my password as "Xyh4g" through run script and I am viewing xml then the password is "Xyh4g".

Now the problem is that when I am trying to log in through username and password="Xyh4g" then I am not able to login,it is showing wrong username or password.Please help how can I set password through script?

1 ACCEPTED SOLUTION

christopheriron
Tera Expert

Hi Anirban,



If you're setting a password through a script you need to use setDisplayValue('Xyh4g'). Otherwise you are setting the post-encrypted password.



Thanks


View solution in original post

5 REPLIES 5

christopheriron
Tera Expert

Hi Anirban,



If you're setting a password through a script you need to use setDisplayValue('Xyh4g'). Otherwise you are setting the post-encrypted password.



Thanks


Hii Chris



I am using the below code in Run Script and getDisplayValue is not working.Can you help




      var text = "";


      var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";


      for( var i=0; i < 8; i++ )


              text += possible.charAt(Math.floor(Math.random() * possible.length));


      workflow.scratchpad.a= text;


      var password= text;



var req_for=current.variables.req_for;



var gr=new GlideRecord('sys_user');


gr.addQuery("sys_id",req_for);


gr.query();


if(gr.next())


{


gr.user_password=password;


gr.password_needs_reset='true';


gr.update();


}



Hi Anirban,



The below show work now.



  var text = "";


      var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";


      for( var i=0; i < 8; i++ )


              text += possible.charAt(Math.floor(Math.random() * possible.length));


      workflow.scratchpad.a= text;


      var password= text;



var req_for=current.variables.req_for;



var gr=new GlideRecord('sys_user');


gr.addQuery("sys_id",req_for);


gr.query();


if(gr.next())


{


gr.setDisplayValue('user_password', password);


gr.password_needs_reset='true';


gr.update();


}



Kind Regards


It worked with gr.user_password.setDisplayValue(password);.Thank you for the information