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.

How to use setAuthentication method in Preview Script Usage link in SOAP Message Function?

Sitansu Subudhi
Tera Contributor

When I click on the Preview Script Usage related link in insert SOAP Message Function, I am provided with the script as shown below. 

find_real_file.png

I am trying to use the below commented code for SOAP message authentication. 

r.setAuthentication(authentication type,profile name);

In my example scenario, I try to use : 

s.setAuthentication('basic', '60545773db73330044247b8239961962'); //Sys ID of Basic Auth Configuration [sys_auth_profile_basic] record

However, I am unable to create any record in the target instance. I have checked the credentials and they are working correctly. I get an error in response body as User Not Authenticated. 

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>User Not Authenticated</faultcode><faultstring>User Not Authenticated</faultstring><detail>Error completing SOAP request</detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

 

I also tried to search for this method in the ServiceNow API Reference at https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=sn_ws-namespace

But, this method seems to be present only in RESTMessageV2 API. How do we use this method for SOAPMessageV2 API as displayed in Preview Script Usage? 

3 REPLIES 3

ChrisBurks
Giga Sage

They have a typo in their example. It should be: setAuthenticationProfile instead of setAuthentication.

s.setAuthenticationProfile('basic','60545773db73330044247b8239961962' )

I have tried that and it gives an error 

com.glide.script.fencing.MethodNotAllowedException: Function setAuthenticationProfile is not allowed in scope global

 

I think this happens because the method is defined for RESTMessageV2 and not SOAP.

Tekin Durmus
Kilo Contributor

Hello,

I'm facing with same issue.Anyone can help me?