How to create sys property and call it in Script include.

VIKAS MISHRA
Tera Contributor

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();
    },

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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();
},

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

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();
},

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Abhijit4
Mega Sage

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

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP