API to search short description + Request type should be 'create a group' + GroupName to get Ticket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2024 07:13 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2024 10:16 PM
@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.
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 01:44 AM
I'm very new in ServiceNow. Is it possible to guide what exactly needs to pass?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 01:52 AM
@11agvikas Please go through the below link to understand the outline of REST API and use REST API Explorer as an initial step,
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
Sujatha V.M.