Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

Skip the service now ticket creation if task source is request

yatishtiwari
Regular Contributor
Regular Contributor

Hi Team,

We have a use case to skip ticket creation if the task source is request. We tried different JSON configurations to fail service ticket creation. Here are the different Create Ticket JSON configurations we have tried

Option -1 – Create Ticket JSON

{

  "ticketidPath": "call2.message.result.number",

  "call": [

    {

      "name": "call1",

      "connection": "acctAuth",

      "url": https://dev.service-now.com/api/now/v1/table/sc_request ,

      "httpMethod": "POST",

      "httpParams": "{}",

      "httpHeaders": {

        "Authorization": "${access_token}"

      },

      "httpContentType": "application/json",

      "successResponses": {

        "statusCode": [

          200,

          201

        ]

      }

    },

    {

      "name": "call2",

      "connection": "acctAuth",

      "url": https://dev.service-now.com/api/now/v1/table/sc_req_item ,

      "httpMethod": "POST",

      "httpParams": "{}",

      "httpHeaders": {

        "Authorization": "${access_token}"

      },

      "httpContentType": "application/json",

      "successResponses": {

        "statusCode": [

          200,

          201

        ]

      }

    }

  ]

}

Result 1- The ticket has been created with blank/default values. So, it looks like somehow, we need to throw an exception from the JSON in case the task source is “Request”.

               yatishtiwari_0-1711058269031.png

Option 2- We tried to put if condition on Access token

"Authorization": "${if(task.requestKey!=null){{access_token}}}"  OR  "Authorization": "${if(arsTasks.source.equals('REQUEST')){{access_token}}}"

Result 2- Tickets for both scenarios were not created with the following exception-

Error in getting Ticket Number. Response: {"call1":{"headers":null,"message":"","statusCode":null,"description":null,"status":"Failed"},"call2":{"message":"Unrecognized character escape (CTRL-CHAR, code 10)\n at [Source: {\

Option 3- We tried to put if condition at the start of Create Ticket JSON

{

"if": { "$(task.requestKey)": null},

"then":

{             

  "ticketidPath": "call2.message.result.number",

  "call": [

    {

      "name": "call1",

      "connection": "acctAuth",

      "url": https://dev.service-now.com/api/now/v1/table/sc_request ,

      "httpMethod": "POST",

      "httpParams": "{\"opened_by\":\"svc_syt01dev\",\"requested_for\":\"${user.firstname} ${user.lastname}\",\"assignment_group\":\"${if(task.endpoint?.customproperty1 == 'LearningandDevelopment'){ 'Learning and Development' } else if(task.endpoint?.customproperty1 == 'ITServiceDesk'){ 'IT Service Desk' } else if(task.endpoint?.customproperty1 == 'FieldServices'){ 'Field Services' } else if(task.endpoint?.customproperty1 == 'PhysicalSecurity'){ 'Physical Security' } else { 'IAM' }}\",\"short_description\":\"ITServiceDesk\",\"description\":\"ITServiceDesk\",\"assigned_to\":\"${task.endpoint?.ownerkey}\"}",

      "httpHeaders": {

        "Authorization": "${access_token}"

      },

      "httpContentType": "application/json",

      "successResponses": {

        "statusCode": [

          200,

          201

        ]

      }

    },

    {

      "name": "call2",

      "connection": "acctAuth",

      "url": https://dev.service-now.com/api/now/v1/table/sc_req_item ,

      "httpMethod": "POST",

      "httpParams": "{\"opened_by\":\"svc_syt01dev\",\"cat_item\":\"IT Security Birthright Access \",\"u_subcategory\":\"Identity Management\",\"request\":\"${response.call1.message.result.number}\",\"requested_for\":\"${user.firstname} ${user.lastname}\",\"assignment_group\":\"${if(task.endpoint?.customproperty1 == 'LearningandDevelopment'){ 'Learning and Development' } else if(task.endpoint?.customproperty1 == 'ITServiceDesk'){ 'IT Service Desk' } else if(task.endpoint?.customproperty1 == 'FieldServices'){ 'Field Services' } else if(task.endpoint?.customproperty1 == 'PhysicalSecurity'){ 'Physical Security' } else { 'IAM' }}\",\"description\":\"ITServiceDesk\"}",

      "httpHeaders": {

        "Authorization": "${access_token}"

      },

      "httpContentType": "application/json",

      "successResponses": {

        "statusCode": [

          200,

          201

        ]

      }

    }

  ]

  }

}

 

Result 3- Save and Test connection failed.

yatishtiwari_1-1711058850725.png

Is there a way to throw an exception  to make sure ticket creation is failed if task source is request?

[This message has been edited by moderator to disable url hyperlink]

 

1 REPLY 1

rushikeshvartak
All-Star
All-Star

use callCondition

"callCondition": "${arstasksObj?.source == 'REQUEST'}",

rushikeshvartak_0-1711071253571.png

 

 


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