- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 11:00 PM
I am doing one rest message integration to send the updated fields data to third party tool from servicenow.
Below is the script include code that i am using to generate the token automatically whenever its expired, so in the code you can see i am setting username and password also, which is hard code.
So now i do not want to hard code the username and password and i want to create one sys property in which i can add username and passoword in one sys property only by ? seprated and then call it in the script inculde .
Questions:
1) How to add username and password both in one system property and do ? seprated.
2) How to call the the property in my script include code and remove the hard coded username and password.
Script include code below:
generateRefreshToken: function(){
var oAuthClient = new GlideOAuthClient();
var params = {grant_type:"password", username:"apttusintegrationuser@aexp.com.amexdev", password: "Amex@12345AS7XksHNV59EcblIMqQQ2Rww"};
var json =new JSON();
var text = json.encode(params);
var tokenResponse = oAuthClient.requestToken('Conga_OAuth_Details', text);
var token = tokenResponse.getToken();
return token.getAccessToken();
},
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 11:06 PM
Hi,
you can create system property of type string and hold the username and password like this separated by :
you can separate it with any special character but I took : colon
apttusintegrationuser@aexp.com.amexdev:Amex@12345AS7XksHNV59EcblIMqQQ2Rww
Then in script include do this
generateRefreshToken: function(){
var oAuthClient = new GlideOAuthClient();
var propertyValue = gs.getProperty("propertyName").split(":");
var userName = propertyValue[0];
var passwordValue = propertyValue[1];
var params = {grant_type:"password", username: userName, password: passwordValue};
var json =new JSON();
var text = json.encode(params);
var tokenResponse = oAuthClient.requestToken('Conga_OAuth_Details', text);
var token = tokenResponse.getToken();
return token.getAccessToken();
},
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 11:06 PM
Hi,
you can create system property of type string and hold the username and password like this separated by :
you can separate it with any special character but I took : colon
apttusintegrationuser@aexp.com.amexdev:Amex@12345AS7XksHNV59EcblIMqQQ2Rww
Then in script include do this
generateRefreshToken: function(){
var oAuthClient = new GlideOAuthClient();
var propertyValue = gs.getProperty("propertyName").split(":");
var userName = propertyValue[0];
var passwordValue = propertyValue[1];
var params = {grant_type:"password", username: userName, password: passwordValue};
var json =new JSON();
var text = json.encode(params);
var tokenResponse = oAuthClient.requestToken('Conga_OAuth_Details', text);
var token = tokenResponse.getToken();
return token.getAccessToken();
},
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 11:40 PM
Hi,
Password cannot be stored with string value as it will be visible to many users which is not best approach.
So I suggest to have two different properties with name aexp_user_id with type string and aexp_password with type password. Use it in script as shown below,
generateRefreshToken: function(){
var aexpID=gs.getProperty("aexp_user_id");
var aexpPassword=gs.getProperty(" aexp_password ");
var oAuthClient = new GlideOAuthClient();
var params = {grant_type:"password", username:aexpID, password: aexpPassword};
var json =new JSON();
var text = json.encode(params);
var tokenResponse = oAuthClient.requestToken('Conga_OAuth_Details', text);
var token = tokenResponse.getToken();
return token.getAccessToken();
},
Let me know if you have any further questions.
Please mark this as Correct or Helpful based on the impact.
Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP