Does a REST API can be called from a UI Action

wakespirit
Kilo Guru

Dear all,

I have initially a REST API Post operation to Jira Service Desk which is running on Incident record Insert operation.

That works actually correctly.

Now the question I have is does the REST APi call can be executed from a UI Action ?

regarsd

1 ACCEPTED SOLUTION

Chalan B L
Giga Guru

Yes, you can call it from UI action

Rest/Soap APIs can be called from any server side [Business rule, UI Action etc]

 

Ex:

We have configured an integration using SOAP message and used an third part "Oracle" Endpoint

Our requirement was whenever you hit on "UI Action button - Submit to Oracle" the integration should trigger

so we have called the soap message where you could ready script from soap message Related link [Preview script usage]

 

Mark the answer as correct and helpful if it helped you..!!!

 

Regards,

Chalan

View solution in original post

9 REPLIES 9

Alikutty A
Tera Sage

Yes you can execute a REST API call from a UI Action, If you have setup your JIRA REST Message in Service Now.

Thanks!

Here is a sample code that you could use to call REST via UI action.

var requestBody;
var responseBody;
var status;
var sm;
try{
	sm = new sn_ws.RESTMessageV2("REST MESSAGE", "post");
	sm.setBasicAuth("admin","admin"); //Authentication
	sm.setStringParameter("symbol", "NOW");  //Sample data to pass
	response = sm.executeAsync(); //Might throw exception if http connection timed out or some issue with sending request itself because of encryption/decryption of password.

	response.waitForResponse(60);// In seconds. Wait at most 60 seconds to get response from ECC Queue/Mid Server //Might throw exception timing out waiting for response in ECC queue.

	responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
	status = response.getStatusCode();
} catch(ex) {
	responseBody = ex.getMessage();
	status = '500';
} finally {
	requestBody = sm ? sm.getRequestBody():null;
}
gs.log("Request Body: " + requestBody);
gs.log("Response: " + responseBody);
gs.log("HTTP Status: " + status);

Chalan B L
Giga Guru

Yes, you can call it from UI action

Rest/Soap APIs can be called from any server side [Business rule, UI Action etc]

 

Ex:

We have configured an integration using SOAP message and used an third part "Oracle" Endpoint

Our requirement was whenever you hit on "UI Action button - Submit to Oracle" the integration should trigger

so we have called the soap message where you could ready script from soap message Related link [Preview script usage]

 

Mark the answer as correct and helpful if it helped you..!!!

 

Regards,

Chalan

Thamks great.

Once last question :

I have define a UI action which is display as a Button on my form.
When user click on the button the data are send to Jira Service Desk.

This work well, but what I woould like to do is that once it is send how can I desable the button for now clicking a second time ?

regards