Setting oAuth profile not working if rest message does not have oAuth presetIssue If RESTMessageV2 method is being used in order to set the authentication profile to an OAuth 2.0 profile, it only works if you set on the REST message itself the authentication type to "OAuth 2.0". If you leave it blank (e.g. you want to determine by runtime if you want to use basic or oauth) the method "setAuthenticationProfile" does not set the OAuth profile. Steps to reproduce:1. Create a new REST Message called "My REST Message"2. Add a rest message function with e.g. GET3. Ensure that you do not set any value to the authentication type field on the rest message or its function.4. Create any sample Oauth Profile which is working to get a authorization token5. Execute the script below: sm = new sn_ws.RESTMessageV2("My REST Message", "get");sm.setAuthenticationProfile('oauth2', 'addSysIDOfNewlyCreatedProfileInStep4'); //set auth profile to an OAuth 2.0 profile record.sm.setLogLevel('all');var response = sm.execute() 6. Check outbound http logs and notice that no authorization token is sent with the message as the profile has not been applied7. Go back to the REST message and set the authentication type to "OAuth 2.0" and use any oauth profile, but NOT! the one from step 4.8. Repeat step 5 and 6 and notice that the token from the profile in step 4 is used for the executionCauseAnything specified in the scriptable layer when using RESTMessageV2 will override whatever is configured on the REST Message record. If there isn't an explicit authentication type + profile specified on their REST Message record, whatever is specified at runtime will be used. Please note however that the requestor profile is required in order for the token to be generated, so if you don't explicitly specify an authentication profile on the REST message then they must call "setRequestorProfile" explicitly, otherwise requestor profile will be null and token will not be generated.ResolutionHere are some permutations for oAuth using RESTMessageV2 referring to both the top-level REST Message record and any of its contained HTTP method records: 1. REST Message does not contain a specific oAuth profile, you need to explicitly call both "setAuthenticationProfile" and "setRequestorProfile".2. REST Message does contain a specific oAuth profile. you can, if you want to override the profile specified on the REST Message record, call "setAuthenticationProfile". In this case "setRequestorProfile" is not needed since it is tied to the REST Message.3. REST Message does contain a specific oAuth profile. If you need to use the oAuth profile specified in the REST Message, you don't need to call "setAuthenticationProfile" and "setRequestorProfile" methods as they will be handled automatically.Related Linkshttps://developer.servicenow.com/dev.do#!/reference/api/paris/server/sn_ws-namespace/c_RESTMessageV2API