- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
08-12-2024 10:36 PM - edited 08-12-2024 10:42 PM
Example Fix script on Incident :
This code is written in JavaScript and is used to interact with a ServiceNow instance. It retrieves information about an incident record and prints out some of its attributes.
Here's a breakdown of what the code does:
1. `var grInc = new GlideRecord('incident');`: This line creates a new GlideRecord object, which is a way to interact with data in ServiceNow. The record type is set to 'incident', which means it's an incident record.
2. `incSysId = '6be681e4334092107915af255d5c7b4a';`: This line sets the `incSysId` variable to a specific incident record's system ID.
3. `grInc.get(incSysId);`: This line retrieves the incident record with the specified system ID.
4. `var servceId = grInc.business_service.toString();`: This line retrieves the business service associated with the incident record and converts it to a string.
5. `var response = new CustomCSDMGlideAjaxUtils().getService(servceId);`: This line calls a method named `getService` on an object of type `CustomCSDMGlideAjaxUtils`, passing the `servceId` as a parameter. This method is likely to retrieve information about the business service.
6. `var responseObj = JSON.parse(response);`: This line converts the response from the `getService` method to a JSON object.
7. `var impact = responseObj.impact;`: This line retrieves the impact value from the JSON object.
8. `var group = responseObj.group.toString();`: This line retrieves the group value from the JSON object and converts it to a string.
9. `gs.print( " servceId= "+ servceId + " response= " + response + "responseObj= " + responseObj + "impact=" + impact + " group=" + group);`: This line prints out the values of the `servceId`, `response`, `responseObj`, `impact`, and `group` variables. The `gs.print` function is used to print out the values.
The output of this code would be the values of the incident record's business service, the response from the `getService` method, the JSON object, the impact, and the group.
Example Business rule on change request :
This is a JavaScript code written in ServiceNow, specifically a Business Rule (BR) script. It's designed to execute a set of actions when a Change Request is created from another task record, such as an Incident or Problem.
Here's a breakdown of what the code does:
1. It defines a function `executeRule` that takes two parameters: `current` and `previous`. The `previous` parameter is null when the script is executed asynchronously.
2. The function checks if the Change Request was created from another task record by checking if the `current.business_service` property is not null. If it is, the script continues to execute.
3. It creates a new instance of the `CustomCSDMGlideAjaxUtils` class, which is a custom class that extends the `AbstractAjaxProcessor` class. This class is used to make AJAX calls to retrieve data from the ServiceNow instance.
4. The script calls the `getService` method on the `CustomCSDMGlideAjaxUtils` instance, passing the `servceId` (which is the ID of the business service associated with the Change Request) as a parameter.
5. The `getService` method returns a JSON response, which is parsed into a JavaScript object using the `JSON.parse` method.
6. The script extracts the `impact` and `group` values from the JSON object and assigns them to the `impact` and `assignment_group` properties of the Change Request record, respectively.
7. The script uses the `JSUtil.notNil` method to check if the `impact` and `group` values are not null before assigning them to the Change Request record.
In summary, this script is designed to populate the `impact` and `assignment_group` properties of a Change Request record when it is created from another task record. It uses a custom class `CustomCSDMGlideAjaxUtils` to make an AJAX call to retrieve the required data.
Example client script on problem:
I'd be happy to explain this code to you.
This code is written in ServiceNow's JavaScript and is used to auto-populate the `impact` and `assignment_group` fields on a form based on the value selected in the `business_service` field.
Here's a breakdown of what the code does:
1. The `onChange` function is called whenever the value of the `business_service` field changes.
2. The function checks if the value is being loaded (i.e., it's not a real-time change) or if the value is empty. If either of these conditions is true, the function returns without doing anything.
3. The function creates a new instance of the `GlideAjax` class, which is used to make an AJAX call to a script include named `CustomCSDMGlideAjaxUtils`.
4. The function adds two parameters to the `GlideAjax` object: `sysparm_name` is set to `getService`, and `sysparm_service` is set to the value of the `business_service` field.
5. The function calls the `getXMLAnswer` method on the `GlideAjax` object, passing in the `ManagerParse` function as a callback function. This means that when the AJAX call returns a response, the `ManagerParse` function will be called with the response as an argument.
6. The `ManagerParse` function takes the response from the AJAX call and parses it as JSON.
7. The function extracts the `impact` and `group` values from the JSON response and sets the corresponding fields on the form using the `g_form.setValue` method.
In summary, this code is used to auto-populate the `impact` and `assignment_group` fields on a form based on the value selected in the `business_service` field. It uses a script include named `CustomCSDMGlideAjaxUtils` to make an AJAX call to retrieve the required data.
Script include :
This code is written in JavaScript and defines a custom class called `CustomCSDMGlideAjaxUtils` that extends the `AbstractAjaxProcessor` class. This class is used to process AJAX requests in ServiceNow.
The `getService` method is defined in this class, which takes a `serviceId` parameter. This method is used to retrieve information about a service record in ServiceNow.
Here's a breakdown of what the `getService` method does:
1. It sets some default values for variables: `impact`, `group`, `service`, `serviceCrit`, and `busCriticality`.
2. It checks if a `serviceId` parameter is provided. If it is, it sets the `service` variable to that value. Otherwise, it sets the `service` variable to the value of the `sysparm_service` parameter.
3. It creates a new GlideRecord object for the `cmdb_ci_service` table and retrieves the record with the specified `service` value.
4. It retrieves the `support_group` and `busines_criticality` values from the service record and sets them to the `group` and `busCriticality` variables respectively.
5. It creates a new GlideRecord object for the `u_impact_data_lookup` table and constructs a query to retrieve the `u_impact` value based on the `busines_criticality` value.
6. It executes the query and retrieves the `u_impact` value if a record is found.
7. It builds a JSON object with the `impact` and `group` values and returns it as a string using `JSON.stringify`.
The `type` property is set to `'CustomCSDMGlideAjaxUtils'` to identify this class as a custom AJAX processor.
This class can be used to make server-side or client-side calls to retrieve information about a service record in ServiceNow. The `getService` method can be called with a `serviceId` parameter to retrieve the service information.
- 394 Views