How to execute an API call from clicking a button on the Service Catalog Order form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2019 04:56 AM
Hi,
I have read several SNOW docs and many posts from the community and I am still not able to get this to work. It could be my lack of experience with web or sp coding although I do support the Service Catalog and Service Portal at our site. Or I'm just not looking for the correct info.
We have a process in place now that utilizes REST to do the same API call that I want to use. Besides the REST message there is a Script Include and a Catalog Client (onChange) Script. On the order form there is a single line text variable where the user enters an ID. This ID is a unique field in an external non-servicenow database. Once the focus moves out of the field the API call is executed and several other variables are populated from data in that database.
Now we want to expand on this functionality by taking the same ID and performing another API call and this time retrieving ALL the fields of the record instead of just the few we need in the RITM/SCTask records. When we retrieve them we just want to display them in a pop up form for review. Once the review is complete then the user clicks the Close button and the form goes away.
Once I get this working my next goal is to have this same functionality available in RITM and SCTask records via a Related Link or a button on the form.
First things first however. I have created a Widget to act as a button on the form under the aforementioned ID field. I want to take that input and use it in my separate call to retrieve the data.
I copied some code from elsewhere in the tool using spModal and I can display the pop-up form with a Title at the top and a Close button at the bottom. I have since been able to add a few column headers and if I ever get this to work hopefully the appropriate data will display under those headers.
I've been trying to utilize the existing code so I don't have to completely recreate the process but I am not able to successfully access the other database. I have tried several ways to do this, mostly from within the Widget trying to run the Script Include.
The widget is running off of another variable I created as it is how I get it to display on the Order Form.
I'm not looking for anyone to provide code for the whole process but at least as a start, a way to get to the external database from the Widget. Unless of course there is a better way to do this altogether.
Thanks,
John

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2019 10:28 AM
running the Script Include within the widget should work. what is the issue you are facing while doing this?
- on click of a btton function in widget client script should be called .
- with in the function a script include should be called
- within the script include api should be called
- on getting response it is returned from scriprt include to widget client script.
- then invioke the spmodal by passing the received response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2019 10:50 AM
Hi Satheesh,
Thank you for replying. Maybe this is a bit over my head still but the problem is that I don't know how to call the client script when the button is pushed.
Actually two problems.
The first is that my variable is different than the one that is using the client script. My button is a secondary function that is supposed to do almost the same thing. The difference is that I want to display the data in a pop up form instead of writing to variable fields on the order form.
I created another variable to display the button on the form. Maybe this isn't the best way to do it?
The Client Script that currently works is tied to the other variable. The only way I can tie my variable to a client script is to use an onChange type but I don't think that does anything with a button.
The second problem is that I don't know how to code the widget client script to display any data. Or maybe I do but I'm not retrieving any data to test it. So it may actually work once I can retrieve the data. I'll worry about that after.
It looks like I am on the right track as far as the steps but don't know how to effectively execute those steps.
Thanks,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2019 05:31 AM
This is my widget client controller. I believe I copied from the community somewhere. I don't know how or where I can call a client script from here. And I don't know what type of client script I need to use.
function($uibModal, $scope) {
var c = this;
c.openModal = function() {
c.modalInstance = $uibModal.open({
templateUrl : 'modalTemplate' ,
scope: $scope
});
};
c.closeModal = function() {
c.modalInstance.close();
};
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2019 06:08 AM
can you share your html part of your widget.