Announcing the SAVIYNT KNOWLEDGE EXCHANGE unifying the Saviynt forums, documentation, training, and more in a single search tool across platforms. Click HERE to read the Announcement.

ServiceNow connection for creating ticket

Ekata
New Contributor III
New Contributor III

Hi Team,

I have requirement for creating ticket in ServiceNow where we need to call 2 jsons under create ticket json one for getting the data and the other is to create it with 2 different APIs.

Below are the APIs provided by client with is working in postman:

1. GET--> https://domain.service-now.com/api/now/table/sys_user?sysparm_query=active%3Dtrue%5Euser_name%3D{{eC...

2. POST--> https://domain.service-now.com/api/sn_sc/servicecatalog/items/801dfde6db9bd700677d3437b996198e/order...

The body in POST method should contain the below parameters:

{
    "sysparm_quantity":"1",
    "variables":{
        "case_code":"06f9b8fa1b9360108c122066b04bcb30",
        "request_type":"Request a Desktop",
        "requested_for":"9d73bbf71bbf9590360da8e82d4bcb68",
        "physical_location":"EU2"
    }
}
 
I tried to create a json which is:
{
   "call":[
      {
         "name":"call1",
         "connection":"userAuth", 
         "url":"https://domain.service-now.com/api/now/table/sys_user?sysparm_query=active%3Dtrue%5Euser_name%3D${us...,
         "httpMethod":"GET",
         "httpHeaders":{
            "Authorization":"${access_token}"
         },
            "httpContentType": "application/json",
            "ticketidPath": "result[0].sys_id",
             "successResponses": {
        "statusCode": [
          200,
          201
        ]
             },
            "unsuccessResponses":{
            "error.message":"Operation Failed"}
      },
      {
         "name":"call2",
         "connection":"userAuth", 
         "url":"https://domain.service-now.com/api/sn_sc/servicecatalog/items/801dfde6db9bd700677d3437b996198e/order...,
         "httpMethod":"POST",
          "httpParams":"{\"sysparm_quantity\":\"1\",\"variables\":{\"case_code\":\"06f9b8fa1b9360108c122066b04bcb30\",\"request_type\":\"Request a Desktop\",\"requested_for\":\"${response.call1.message.result[0].sys_id}\",\"physical_location\":\"EU2\"}}",
         "httpContentType": "application/json",
         "httpHeaders":{
            "Authorization":"${access_token}"
         },

            "ticketidPath": "result[0].request_number",
            "ticketStatusValue": [
                "Closed",
                "Closed Complete",
                "Resolved"
            ],
            "disContinueStatusValue": [
                "Closed Incomplete",
                "Closed Skipped"
                ],
      "successResponses": {
        "statusCode": [
          200,
          201
        ]
      },
        "unsuccessResponses":{
            "message":"Operation Failed"}
}
]
}
 
However, the response we received in task is NULL. There is no error message found in logs as well. How can we use multiple APIs here.
Please suggest.
 
regards,
Ekata
9 REPLIES 9

Ekata
New Contributor III
New Contributor III

Error in logs:

ERROR rest.RestProvisioningService  - Error in createNewServiceTicketjava.lang.NullPointerException: Cannot invoke method startsWith() on null object\n","stream":"stdout","time":"2022-12-26T12:33:14.095095788Z"}"

One of the value is coming as blank 


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

Hi,

How can we achieve it? Any idea.

Regards,

Ekata

Can you store requestor for in dynamic attribute and try instead of multi call


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

Hi,

Are you saying to assign it as variable like below:

"accountIdPath":"call1.message.result.sys_id"

Or is there anything else which I am missing.

Regards,

Ekata

 

sampath18
Regular Contributor II
Regular Contributor II

Hi @rushikeshvartak  I work with Ekata who created this discussion. the reason why we  are doing multi calls are to get the sys_id of individual user object from servicenow which is later used for creating the service request. In postman we are able to do this in two calls one with GET call which returen sys_id of a users when passed username as query string.

In second call we will use sys_id of servicenow and create request item in snow. So in of the forum link (https://forums.saviynt.com/t5/general-discussions/multiple-api-calls-for-rest-connector-in-createacc...)they did the same and mentioned it is working. But in our case it is not working. In the logs it is returning Null pointer exceptions. So it is unclear what is not getting passed. we also verified connection that is working well.

It would be very helpful if we can get some help here from saviynt side.

Thanks
Sampath

Can you post the call1 output? Also for testing purpose did you try to hardcord the sys_id of requestor in requested_for parameter of call2 and see if that works?


Regards,
Saathvik
If this reply answered your question, please Accept As Solution and give Kudos to help others facing similar issue.

sampath18
Regular Contributor II
Regular Contributor II

Hi @sk  I hope you have checked my below responses which answers your queries. So please let us know if you can assist us on this issue.

Thanks

sampath18
Regular Contributor II
Regular Contributor II

Hi,

Yes, below is postman output of call1.

during call1 we have to pass username as query string in the url, So below is how we tried to do. can you please verify is it right way to pass username in url

"https://******dev.service-now.com/api/now/table/sys_user?sysparm_query=active%3Dtrue%5Euser_name%3D${user.username}&sysparm_display_value=true&sysparm_fields=first_name,last_name,user_name,email,sys_id&sysparm_limit=1",

 

{
    "result": [
        {
            "sys_id""d2f3055a1b73095007da62c6b04bcb82",
            "user_name""999970191",
            "last_name""Dev Test",
            "first_name""Sophie",
            "email""Saif.DevTest@domain.com"
        }
    ]
}
 
Also, when i hardcode the sys_id and created a ticket for single user then it is able to create request successfully.
 

{
"call": [

{
"name":"call1",
"connection":"userAuth",
"url":"https://domaindev.service-now.com/api/sn_sc/servicecatalog/items/801dfde6db9bd700677d3437b996198e/or...",
"httpMethod":"POST",
"httpParams":"{\"sysparm_quantity\":\"1\",\"variables\":{\"case_code\":\"06f9b8fa1b9360108c122066b04bcb30\",\"request_type\":\"Request a Desktop\",\"requested_for\":\"d2f3055a1b73095007da62c6b04bcb82\",\"physical_location\":\"EU2\"}}",
"httpHeaders":{
"Authorization":"Basic **********"
},
"httpContentType": "application/json",
"ticketidPath": "result.request_number",
"ticketStatusValue": [
"Closed",
"Closed Complete",
"Resolved"
],
"disContinueStatusValue": [
"Closed Incomplete",
"Closed Skipped"
],
"successResponses": {
"statusCode": [
200,
201
]
},
"unsuccessResponses":{
"message":"Operation Failed"}
}
]
}

 

Thanks
Sampath

[This post has been edited by a Moderator to remove sensitive information.]