API to search short description + Request type should be 'create a group' + GroupName to get Ticket

11agvikas
Tera Contributor

Snag_13019da.png

 Need API to search short description + Request type should be 'create a group' + GroupName to get Ticket no . Please help on this..its a URGENT

@Ankur Bawiskar @Sujatha V M @Robbie @Community Alums 

3 REPLIES 3

Sujatha V M
Kilo Patron
Kilo Patron

@11agvikas  Below is the basic outline of script include for REST API. Modify it accordingly. 

 

//This method is to Create a <Record> from ServiceNow    

createRecord: function(record) { 

 

        try {

            //Fields Data to be passed from ServiceNow

            var shortdescription = record.variables.<variable name>.toString();                      //Short Description           

            var request_type = record.variables.<variable name>.toString();                           //Request Type

            var recID = record.sys_id.toString();                                                                          //RITM/SCTASK ID

            var recnumber = record.number.toString();                                                             //RITM/SCTASK Number           

            var groupName = record.variables.<variable name>.toString();                            //Group Name    

            var request;   

            var instance_env = gs.getProperty('instance_name');                                           //Get the Instance Name

        

            if (instance_env == 'dev' || instance_env == 'qa') {                                                //Default use Non-Prod End points

                request = new sn_ws.RESTMessageV2('<Rest Message Name>', '<Rest Method like Create/Update>');

            }

            if (instance_env == 'prod') {                                                                                           //Change Prod End point

                request = new sn_ws.RESTMessageV2('<Rest Message Name>', '<Rest Method like Create/Update>');

            }

           

            //Add Request Log, if required.

            //Set Request Body

            var reqbody = {};

            reqbody.fields = {};

                      <Define your fields in Request Body>

            var strRestBody = JSON.stringify(reqbody);

            request.setRequestBody(strRestBody);

            response = request.execute();                                                                                      // Execute the Request

                              

            var responsebody = response.getBody();                                                                   //Parse Response

            var res = JSON.parse(responsebody);

         

            var statusCode = response.getStatusCode();

            if (statusCode == 201) {               

                record.comments = <Add your comments>; 

             } else {

                record.comments = "Unable to create.\n" + "StatusCode:" + statusCode + "\nResponse: " + response.getBody();

            }

            record.update();

        } catch (ex) {

            gs.log(ex.message);

        }

    },

    type: '<Script Include Name>'

});

 

Note : Add logs for validation. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

 

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

I'm very new in ServiceNow. Is it possible to guide what exactly needs to pass?

@11agvikas  Please go through the below link to understand the outline of REST API and use REST API Explorer as an initial step, 

 

https://docs.servicenow.com/bundle/washingtondc-api-reference/page/integrate/inbound-rest/concept/c_...

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.