Build a Get CR Notes by CI Relation HTTP Action
Build a Get CR Notes by CI Relation HTTP Action
Let’s walk through a tutorial on building an action with ServiceNow. In this case we will build the “Lookup Account By Name” action.
-
Once in Agent Studio, navigate to “HTTP Actions”
-
On the top right, click the “CREATE” button
-
On the top right next to "Test" you will see an "Import" icon button. Click that and you should see the following dialog. This allows you to easily import HTTP actions if you have a cURL command.
-
Paste the following cURL command into the dialog and click "Import"
curl --location 'https://platformdemo33b.service-now.com/api/now/table/change_request?sysparm_query=cmdb_ci%3D{{ci_sys_id}}%5Estate%3D3&sysparm_limit=10&sysparm_fields=close_notes' -
You should see that all the fields you need for your API call have populated. Take a look at the Query Params and notice the field in curly brackets - that being "ci_sys_id". These are the variables that will be populated as part of the API call. We are looking up Change Requests by it's related ci_sys_id, so this will be dynamically passed to the HTTP Action as extracted from the conversation.
-
Since we are using a shared ServiceNow Sandbox instance, the connector has already been set up for you. Choose “Inherit from existing connector” and select “ServiceNow”.
-
Now navigate to “Input Args” - you should see that the ci_name variable has been detected in the API call and is of type “string” which is correct. In order to properly test that the action has been set up correctly, we can provide example values and test the call before publishing.
-
Let's populate the ci_sys_id input argument and test the API call. Click the pencil icon to open it up. Provide an example of a ci_sys_id - for testing purposes you can use 469fbb4ea9fe1981016af7bf81d27e41. Remember to make sure you fill in the description and check the "Required" box and click"Save". The description is important since it tells Moveworks how to ask for this argument.
- Click the TEST button. At the bottom in the Console you should see a 200 with a response that looks something like screenshot below. NOTE: Typically this API call would return a lot of information we don't need, essentially everything about the Change Request. We are leveraging the ServiceNow Encoded Query syntax since we only need the close notes for our purposes.
-
Now we must name our HTTP Action. At the top, select the title bar to name your HTTP Action (see the note below before doing so). Your description can be anything that describes the Action such as “Lookup Change Request Notes by CI”
IMPORTANT: Ensure you name the action in this format ”firstname_lastname_lookup_cr_notes_by_ci”. This will ensure you know you are using YOUR action since there are many people at once doing the same exercise in this environment.On the top right, click the dropdown and choose “Validate”. This will ensure everything is correct before publishing. If everything checks out, choose “Publish”.
You should see the following upon success.
Updated about 4 hours ago