Hi , i have two requirements in servicenow, please explain steps how to do these with the solution
Incident Workflow:
• An incident is created and assigned to Group A.
• Group A analyzes the incident and decides to redirect it to Group B for resolution.
• Group B works on the incident, resolves it, and reassigns it back to Group A for closure or further action.
2. Reporting Requirement:
• You need a report that shows all incidents that have ever been assigned to Group B at any point in their lifecycle, regardless of their current assignment group.
Assistant
To address your requirements in ServiceNow, we'll break them down into two sections: Incident Workflow and Reporting Requirement.
1. Incident Workflow
To implement the incident workflow where incidents are assigned to different groups for resolution, you can use the following steps:
Step-by-Step Instructions for Incident Workflow:
Create/Set Up Group A and Group B:
Ensure you have two groups created in ServiceNow: "Group A" and "Group B".
Navigate to User Administration > Groups, and verify or create the groups as needed.
Incident Creation:
Configure your incident creation process, usually done through the self-service portal or directly in the Incident table.
When creating an incident, it will be automatically assigned to Group A.
Implement a Redirect Mechanism from Group A to Group B:
Configure a Business Rule or use an Approval Workflow to allow Group A to reassign the incident to Group B.
To create a Business Rule:
Navigate to System Definition > Business Rules.
Click on “New” to create a new business rule that triggers when the incident is updated.
You can set conditions such as when the "Assignment group" changes to Group B, and ensure to run this before or after the record is updated.
Update Incident by Group B:
Group B will receive the incident assigned to them, work on it, and then resolve the incident.
They can change the state to “Resolved” or “Closed” based on your processes.
They can also change the assignment group back to Group A.
Involve Notifications:
Set up notifications in ServiceNow to alert both groups when incidents are assigned, redirected, or reached their resolution.
Navigate to System Notification > Email > Notifications and configure email alerts for those specific assignments or updates.
Important Note:
While you can set automated workflows using Flow Designer as well, the steps above detail the basic manual handling and reassignment process between groups.
2. Reporting Requirement
To create a report that shows all incidents assigned to Group B at any point in their lifecycle, you can follow these steps:
Step-by-Step Instructions for Reporting:
Navigate to Reports:
Go to Reports > View / Run.
Create a New Report:
Click on Create a report or use "New" to define a report from scratch.
Select Table:
Choose the Incident [incident] table for your report.
Define Conditions:
Set up the conditions for filtering incidents. Use the following conditions:
Use "Activity" from the "Related Lists" such as "Change History" to specify the past assignments.
Here’s how to structure your queries:
In the Group B Assignment History, you might have to add conditions such as:
Assigned to Group is Group B.
State is not Closed (if you want to check all assignments).
Create a calculated field if needed to check the history of assignments.
Choose Report Type:
Select the appropriate report type (e.g., List, Pie Chart, Bar Chart, etc.) based on how you want to visualize the data.
Configure Report Items:
Select the fields you wish to display in the report, like incident number, description, state, and incident assignment group.
Sharing the Report:
After saving it, you can share the report as needed or configure dynamic filters for user access based on their roles.
Save and Run:
Save the report and run it to ensure it captures all historical incidents assigned to Group B.
Summary
With these steps, you will have established a seamless incident workflow and created a report that meets your reporting requirements. Always remember to verify your permissions and the appropriate module access to ensure that both groups and report creators have the necessary rights to perform actions and view information.
User
hi i want a report of all the incidents that was currently assigned to my group or assigned to my group in past, is it possible to create a report in servicenow, if yes, how to create this
Assistant
Yes, you can create a report in ServiceNow that shows all incidents currently assigned to your group and those that have been assigned to your group in the past. Here’s how you can do that step by step:
Step-by-Step Instructions to Create the Report
Log in to ServiceNow:
Make sure you have the appropriate permissions to create and view reports.
Navigate to Reports:
Go to Reports > View / Run in the Application Navigator.
Create a New Report:
Click on Create a Report (you may also see a “+” button or an option for "New" depending on your version of ServiceNow).
Select Table:
Choose the Incident [incident] table as the source for your report.
Set Up the Report Conditions:
In the report builder, you will need to define the conditions to filter incidents that are currently assigned to your group or were assigned to your group in the past.
Use the following condition setup:
Condition 1: Current Assignment Group is Your Group (this captures currently assigned incidents).
Condition 2: OR
Condition 3: Assignment Group wasYour Group (this captures historical assignments).
This may look like:
code
[Assignment Group] is [Your Group]
OR
[Assignment Group] was [Your Group]
Note: If “was” or the "Assignment Group" has audit fields, you may need to check your specific instance for how historical data is logged.
Customize the Report:
Choose the report type that suits your needs (e.g., List, Pie Chart, Bar Chart).
Select fields to display in the report. Common fields include:
Incident Number
Short Description
State
Assignment Group
Created Date
Resolved Date
You can also add filters to only show incidents that are relevant to you.
Group and Sort Options:
User
was operator not present in servicenow
Assistant
In ServiceNow, the "was" operator is not a standard operator available in the report conditions or filters. Instead, ServiceNow has a different way of handling historical data through Audit fields and Activity logs.
Retrieving Historical Assignment Data
If you need a report that includes incidents historically assigned to a group, you'll typically do this through ServiceNow’s Audit History Table or by using scripted filters that access the incident assignment history.
Approaches to Create the Desired Report
1. Using Incident History Records
To show incidents that were assigned to a specific group at any time in the past:
Create a New Report:
Navigate to Reports > Create New.
Select the Table:
Choose the Incident [incident] table.
Set the Conditions for Current Assignments:
Use:
Assignment Group is Your Group
Combine with Incident History:
While constructing your report, you can look into using Join Conditions with the Incident History. The assignment history might be in a related list or external table.
Using a Business Rule or Scripted Filter:
If available, you may enhance the report using a Business Rule or custom Script Include to aggregate the assignment change data and pull any past assignments.
2. Creating a Custom Report Using Data from the Activity Table
You can create an advanced report that pulls from the Activity [sys_audit] or Incident [incident] table where you could look at historical assignments:
Create a New Report:
Navigate to Reports > Create New.
Choose the Source Table:
Select Incident [incident].
Script Condition:
In the condition builder, use a scripted query to fetch incidents where the assignment group matched your group at any point in the history.
User
not possible
Assistant
I apologize for any confusion earlier. If the "was" operator is not available directly in ServiceNow for creating reports, you can utilize existing functionalities more effectively. Let's go over a practical approach to achieve your requirement of showing incidents currently assigned to your group or previously assigned to your group.
Creating a Report for Current and Historical Assignments
Since ServiceNow does not allow straightforward use of historical conditions in the report builder, you can achieve this using a combination of queries. Here’s an adjusted method that will help you access both current and historical assignments of incidents to your group:
Method 1: Using Reporting with Filters
Create a New Report:
Navigate to Reports > Create New.
Select the Table:
Choose Incident [incident].
Set Conditions for Currently Assigned Incidents:
Add a condition for the current assignment:
Assignment GroupisYour Group (this captures currently assigned incidents).
Add Historical Data:
Unfortunately, as previously mentioned, you cannot use "was" directly. Instead, use the Incident Audit or a similar mechanism indirectly by creating two separate reports or learning how to leverage the historical data indirectly.
Create a Separate Report to Check Historical Data:
To get past assignments, create a report from the sys_audit table using conditions to filter where documenttable equals incident and field equals assignment_group.
Example for the script or logical filter you can set:
Where field: assignment_group
Where new_value: [Your Group Sys_ID]
Note: The current assignment can be fetched by the regular incident table querying.
Combine Reports:
You will have two reports: one for current assignments and one querying the history.
You can export them in a dashboard where users can see both current and historical incidents linked to your group.
Method 2: Using a Dashboard
User
i want that in catalog item, if any person fill ABC value in description variable then in variables section in the RITM view, it will show with one prefix like PRE: ABC
Assistant
To achieve the requirement of prefixing a value entered in a catalog item's description variable with "PRE: " when viewed in the Requested Item (RITM) form, you can use a combination of Client Scripts and Business Rules in ServiceNow. Here’s how to implement this step-by-step:
Step 1: Create or Update the Catalog Item
Navigate to the Catalog Item:
Go to Service Catalog > Catalog Definitions > Maintain Items.
Select the catalog item you want to modify or create a new one.
Make Sure the Description Variable Exists:
Ensure there is a variable labeled "Description" (or any appropriate name you’ve assigned).
If it doesn’t exist, you can create a new Variable:
Under the Variables related list, add a new variable of type "Single Line Text" or "Multi-Line Text" with the name "Description".
Step 2: Create a Business Rule to Update the RITM Variable
You need to create a Business Rule that will change the display value of the description variable when the RITM is created or updated.
Navigate to Business Rules:
Go to System Definition > Business Rules.
Create a New Business Rule:
Click on New to create a new Business Rule.
Configure the Business Rule:
Name: Provide a name like “Prefix Description Variable”.
Table: Set it to Requested Item [sc_req_item].
Advanced: Check the Advanced box to open the script editor.
When to run: Set this to after.
Insert: Checked (to execute when an RITM is created).
Update: Checked (to execute when the RITM is updated).
Script Section:
In the script section, you will add a script to modify the description variable. Use the following script as a reference:
javascript
User
not working
Assistant
I apologize for the inconvenience. Let's troubleshoot this step-by-step to ensure we correctly implement the desired functionality to prefix the description in a catalog item with "PRE: " when displayed in the RITM view.
Steps to Implement Prefixing for a Catalog Variable
Assumptions:
You have a catalog item with a variable for "Description".
You want to see this prefixed value in the RITM variables section.
Step 1: Verify the Variable Setup
Access the Catalog Item:
Navigate to Service Catalog > Catalog Definitions > Maintain Items.
Open your catalog item.
Check Variables:
Make sure your description variable is correctly set up (e.g., "Description"), and it is of type "Single Line Text" or "Multi-Line Text".
Step 2: Create a Business Rule
Let's create or update the Business Rule to ensure we are triggering it appropriately.
Create a New Business Rule:
Navigate to System Definition > Business Rules.
Click on New to create a new Business Rule.
Business Rule Configuration:
Name: Set a name (e.g., “Prefix Description Variable”).
Table: Select Requested Item [sc_req_item].
Insert: Checked (so it runs when the RITM is created).
Update: Checked (to update if the RITM is modified).
Advanced: Check this box to open the scripting area.
Script Section:
Use the following script in the Script field (ensure you update description to the correct variable name):
javascript
User
business rule is not working on after insert
Assistant
If the Business Rule is not functioning as intended when configured to run "after insert," and you're not seeing the expected prefix in the RITM variables section, here are several steps to troubleshoot and correct the approach.
Key Considerations
Business Rule Timing: The "after" stage of a Business Rule takes place after the record has been inserted into the database.
If you want to change a variable's display in the RITM view, it’s typically better to use an "on insert" Business Rule or a Client Script, as "after" is too late to affect the display of the variable in the user interface.
Client Script Approach: Instead of a Business Rule, you can use a Client Script to prefix the value as the user enters it. This method will allow you to modify the input before the form is submitted and affect how the value is displayed.
Suggested Approach
Implement a Client Script: This is the recommended way to dynamically change the value of the description field as input is made in the Service Catalog form.
Step-by-Step: Create a Client Script
Navigate to the Catalog Item:
Go to Service Catalog > Catalog Definitions > Maintain Items.
Open the catalog item for which you want to apply the prefix.
Add a Client Script:
Scroll down to the Catalog Client Scripts related list.
Click New to create a new Client Script.
Client Script Configuration:
Name: Give it a descriptive name (e.g., “Prefix Description”).
Type: Set to onChange because we want to modify the value when users enter it.
Variable: Select the variable for the description where users will input text.
Script: Use the following code:
javascript
function onChange(control, oldValue, newValue) {
// When the field changes and has a value
if (newValue) {
// Set the new value with the prefix
control.setValue('PRE: ' + newValue);
}
}
User
please change it to onSUbmit, for better user experience
Assistant
Certainly! If you want to use a Client Script that applies the prefix when the form is submitted, rather than on change, you can write an onSubmit Client Script. This way, the prefix will be applied to the value just before the form is submitted, improving the user experience by allowing users to see the change right before submission.
Implementing the onSubmit Client Script
Follow these steps to create an onSubmit Client Script that prefixes the "Description" variable with "PRE: ":
Step 1: Navigate to Your Catalog Item
Go to:Service Catalog > Catalog Definitions > Maintain Items.
Select the Catalog Item that you want to modify.
Step 2: Create a New Client Script
Scroll down to the Catalog Client Scripts related list.
Click New to create a new Client Script.
Step 3: Configure the Client Script
Name: Set a descriptive name, e.g., “Prefix Description on Submit”.
Type: Set the type to onSubmit.
Script: Use the following code:
javascript
function onSubmit() {
// Get the value of the description variable; change 'description' to your actual variable name
var descField = g_form.getValue('description');
// Check if there is a value for the description field
if (descField) {
// Prefix it with "PRE: "
g_form.setValue('description', 'PRE: ' + descField);
}
// Return true to allow form submission
return true;
}
Step 4: Save the Client Script
Save the Client Script.
Step 5: Testing the Client Script
Submit a New Request:
Go to your Service Catalog and fill out the form.
Enter a value in the "Description" field (e.g., "ABC").
Submit the Form:
Click the submit button.
Check the RITM:
After submission, navigate to the Requested Item (RITM) and check the Variables section.
The description should now display as "PRE: ABC" when viewed in the RITM.
Summary
By using an onSubmit Client Script, you can effectively modify the value of the description variable right before the data is submitted. This provides a better user experience because it ensures users see the final formatted value in the RITM without needing to change it manually during input.
Feel free to let me know if you have any further questions or if there's anything else you'd like to customize!
User
working on try it page, but not when i submit the request from on esc portal
Assistant
If the onSubmit Client Script works on the "Try It" page but does not produce the expected behavior when submitting a request from the Service Catalog in the ServiceNow portal (especially in the "Service Portal" or "Employee Service Center"), there are a few factors to consider and troubleshoot.
Recommended Steps to Ensure the onSubmit Script Works in the Service Portal
Check the Variable Name:
Ensure that the variable name used in the script exactly matches the variable's name in your catalog item. Variable names are case-sensitive.
javascript
var descField = g_form.getValue('description'); // Ensure 'description' matches.
Ensure Visibility of the Variable:
Make sure the "Description" variable is visible to users on the Service Catalog item form. If it's hidden or conditionally shown, the script may not execute properly.
Test Without Prefixing Logic:
First, simplify the script to ensure that the onSubmit function is being triggered accurately. You can temporarily remove the prefix logic and just return true to see if the function runs:
javascript
function onSubmit() {
// Simple test log
console.log('onSubmit is triggered.');
// Return true to allow form submission
return true;
}
If you see the console log message when you submit from the Service Portal, the script itself is indeed being called.
Inspect g_form API Support:
Ensure you are using the service portal’s implementation of g_form correctly. Using g_form in Service Portal Client Scripts should work, but if you are using a widget or other complex elements, there might be variations in how forms are processed.
Browser Console for Errors:
Open your browser’s developer tools (usually accessible with F12) and check the Console for any JavaScript errors when attempting to submit your form. This can provide insights if there are issues with your script.
Check for Other Client Scripts:
User
can we create client script on sc_req_item table to change the variable
Assistant
Yes, you can create a Client Script on the sc_req_item table in ServiceNow to change the variable values, but doing so directly on the sc_req_item table is not common for typical use cases. Generally, client scripts are more commonly utilized in the context of catalog items or forms to modify user inputs before they are submitted.
However, if you specifically need to manipulate a variable using a Client Script on the sc_req_item table, it's important to note that this will likely affect all RITMs globally rather than on a per-catalog-item basis.
Steps to Create a Client Script on the sc_req_item Table
Here is how to add a Client Script to modify an existing variable on the sc_req_item table:
Navigate to the Client Scripts:
Go to System Definition > Client Scripts.
Create a New Client Script:
Click on New.
Configure the Client Script:
Name: Provide a name, e.g., “Modify Description on RITM”.
Table: Set it to Requested Item [sc_req_item].
Type: Choose onLoad or onSubmit, depending on when you want the variable change to occur.
onLoad: Changes when the form opens.
onSubmit: Changes right before the form is submitted.
Script Section:
Use the following script to modify your variable. Make sure to replace description with the correct variable name.
Here’s an example for onSubmit:
javascript
function onSubmit() {
// Get the value of the description variable
var descField = g_form.getValue('description'); // Replace 'description' with your actual variable name
// Check if there is a value
if (descField) {
// Prefix it with "PRE: "
g_form.setValue('description', 'PRE: ' + descField);
}
// Allow the form submission
return true;
}
User
there are two description field, one is on variable and one field is on form level
Assistant
Thank you for the clarification! If you have two "Description" fields (one as a variable in the catalog item and another at the form level on the sc_req_item), and you want to manipulate the value of the variable field while submitting the request, here’s how to approach this using Client Scripts correctly.
Goal
You want to prefix the value entered in the variable description field with "PRE: " when the request is submitted, and show it in the RITM view.
Solution Steps
To achieve this, you can create a Client Script on the sc_req_item table to modify the variable value during the submission. Here’s how you can set this up:
Step 1: Identify the Variable Name
Open the Catalog Item:
Navigate to Service Catalog > Catalog Definitions > Maintain Items.
Open the catalog item containing the description variable.
Verify the Variable Name:
Check the variable name for the description variable. It might be something like description or whatever specific name you have created. Note that variable names are case-sensitive.
Step 2: Create the Client Script
Navigate to Client Scripts:
Go to System Definition > Client Scripts.
Create a New Client Script:
Click on New to create a new Client Script.
Configure the Client Script:
Name: Name the script (e.g., "Prefix Variable Description").
Table: Set to Requested Item [sc_req_item].
Type: Choose onSubmit since you want to prefix the value just before the request is submitted.
Script Section:
Use the following sample script, making sure to use the correct variable name for the description:
javascript
User
i want it on onload
Assistant
If you want to prefix the value of the description variable field with "PRE: " on the onLoad event of the form instead of during submission (when the RITM is opened for the first time), you can use an onLoad Client Script.
Creating an OnLoad Client Script
Follow these steps to create an onLoad Client Script that modifies the variable's value when the RITM form is loaded.
Step 1: Navigate to Client Scripts
Go to: System Definition > Client Scripts.
Click on: New to create a new Client Script.
Step 2: Configure the Client Script
Name: Give your script a name (e.g., "Prefix Description Variable on Load").
Table: Set the table to Requested Item [sc_req_item].
Type: Select onLoad.
Step 3: Script Section
In the script field, use the following code:
javascript
function onLoad() {
// Replace 'description' with the actual variable name for your description field
var descVariableName = 'description'; // Ensure this matches your variable name
// Get the value of the description variable
var descriptionValue = g_form.getValue(descVariableName);
// Check if the variable has a value and it does not already start with "PRE: "
if (descriptionValue && !descriptionValue.startsWith('PRE: ')) {
// Prefix the variable value with "PRE: "
g_form.setValue(descVariableName, 'PRE: ' + descriptionValue);
}
}
Step 4: Save and Test
Save the Client Script.
Open an Existing RITM:
Go to the Requested Items list and open an RITM that has the description variable filled in.
Check the Value:
Once the form loads, the description variable should now display the prefixed value as (if it was "ABC" before).
Not yet included in a published release.
Optionally, configure grouping (e.g., by State) or sorting options to better organize the data in your report.
Run and Validate:
Click on Run to generate and view the report. Verify that the data displayed meets your requirements.
Save the Report:
Give your report a descriptive name, such as "Current and Past Incidents for [Your Group Name]".
Choose a visibility option: share with specific users/groups, roles, or make it public.
Save the report.
Schedule and Share (optional):
If you want to regularly check this report, you can schedule it to run at specified intervals by entering the Schedule tab.
You can also share it by creating a dashboard or sending it via email.
Additional Notes
Make sure you have permission to view all incidents and audit records to pull the necessary historical data.
If ServiceNow version updates or customizations affect reporting, sometimes you may need to consult your ServiceNow administrator for more advanced configurations.
If your group has a specific identifier or a custom condition, adjust the conditions accordingly to match your group's criteria.
By following these steps, you will successfully create a report in ServiceNow listing all incidents currently assigned to your group as well as those previously assigned to your group.
For example, you can use GlideRecord queries or custom script reports.
Here's an illustrative script for the filter that you'd put into a scheduled job or Scripted Report:
javascript
var grAudit = new GlideRecord('sys_audit');
grAudit.addQuery('documenttable', 'incident'); // Filter for incidents
grAudit.addQuery('field', 'assignment_group'); // Look for changes in assignment group
grAudit.addQuery('new_value', 'Your_Group_ID'); // Ensure this is the sys_id of your group
grAudit.query();
while (grAudit.next()) {
gs.info(grAudit.documentkey); // Shows incident records
}
Save and Test:
Create the report using above logic, and run to ensure it gathers both current and historical data.
Summary
To report on incidents assigned to your group at any point in their lifecycle in ServiceNow, you will typically need to leverage Audit History or perform a more advanced scripting solution. Since there is no direct “was” operator, using these alternatives allows for the retrieval of historical data in a more flexible manner.
If you find this approach a bit complex, consider reaching out to your ServiceNow administrator for additional assistance, as they might offer insights or existing solution functionalities that can ease the process.
Create a Dashboard:
Navigate to Self-Service > Dashboards and create a new dashboard.
Add Two Report Widgets:
Add one widget for the current incidents assigned to your group (as set above).
Add another widget to show past assignments through the sys_audit query.
Display Both:
This dashboard can now serve as a combined report showing current and historical assignments.
Additional Tools
If you need direct access to detailed reporting or historical data discussions, consider involving a ServiceNow admin or developer who can provide greater insights into utilizing custom tables, scripts, or workflows that might be set up for your specific instance.
Summary
Unfortunately, due to the limitations of reporting features in ServiceNow, directly combining current and past assignment conditions into a single report may not be feasible without customization. Therefore, using separate reports or dashboard widgets can be an effective workaround. For advanced data inquiries, custom scripting or reaching out to your ServiceNow administrator is recommended for optimized solutions tailored to your needs. If you have access to Flow Designer or other automation tools, consider leveraging those for building more complex queries or workflows.
(function executeRule(current, previous /*null when async*/) {
// Variable name for description, replace with your actual variable name
var descVarName = 'description';
// Get the value from the variable
var descValue = current.variables[descVarName];
// Check if the variable is present and has a value
if (descValue) {
// Prefix the description with "PRE: "
current.variables[descVarName] = 'PRE: ' + descValue;
}
})(current, previous);
Save the Business Rule:
Save your Business Rule.
Step 3: Test the Catalog Item
Submit a Request:
Go to the Service Catalog and submit a request using the catalog item you modified.
In the description, enter a value (e.g., “ABC”).
Check the RITM:
After submitting, navigate to the RITM and check the Variables section.
You should see the description variable now displaying as "PRE: ABC".
Note:
This approach will modify the variable every time the RITM is inserted or updated. If you need to ensure that this does not change the original submitted value, you might need to store the original separately if that is a concern.
Additionally, make sure to adjust the variable name in the script (description in this case) to match the actual name of your description variable in the catalog item.
Summary
By following these steps, you can successfully implement a solution in ServiceNow where a specific prefix gets added to a description variable in the RITM view, enhancing clarity and usability in your service catalog. If you have any further questions or specific scenarios, feel free to ask!
(function executeRule(current, previous /*null when async*/) {
// Variable name for the description variable - adjust this name as needed.
var descriptionVarName = 'description';
// Getting the value of the variable
var originalDescription = current.variables[descriptionVarName];
// Check if the variable is defined and has a value before modifying it
if (originalDescription) {
// Prefix it with "PRE: "
current.variables[descriptionVarName] = 'PRE: ' + originalDescription;
}
})(current, previous);
Notes on the Script:
Make sure description matches the exact variable name in your catalog item.
The script checks if the description variable has a value before attempting to prefix it.
Step 3: Save and Test
Save the Business Rule.
Submit a New Request:
Go to your Service Catalog and fill out the catalog item, entering a value in the "Description" field (e.g., “ABC”).
Check the RITM:
After submission, navigate to the RITM (Requested Item) and check the variables section.
The description should now display as "PRE: ABC" in the variables section.
Troubleshooting Steps
If this still is not working, check the following:
Ensure the Business Rule is Active:
Confirm that the Active checkbox is checked in the Business Rule record.
Check Conditions:
Make sure there are no conditions in the Business Rule that would prevent it from executing. For a test, you may want to keep conditions empty to see if it executes.
Verification of Variable Name:
Confirm that the description variable name exactly matches the name used in your catalog item (case-sensitive).
Verify the Scope:
Ensure the Business Rule is in the correct application scope where the catalog item exists.
Review Logs:
After submission, check the system logs for any errors related to the Business Rule in System Logs > All.
Alternative Approach with Client Script
If the Business Rule approach is not yielding the expected result, you could consider using a Client Script to dynamically modify the displayed value. A Client Script would operate in the form before submission:
Example of a Client Script
Navigate to the Catalog Item:
Go back to your catalog item and scroll down to Variables.
Create a New Client Script:
Click on Add in the Catalog Client Scripts related list.
Sample Client Script:
javascript
function onChange(control, oldValue, newValue) {
if (newValue) {
// Ensure you set it like this to update the variable's display value
control.setValue("PRE: " + newValue);
}
}
Type: Set the type to onChange.
Variable: Set the variable to your Description variable.
Summary
If the initial Business Rule method isn’t behaving as expected, reviewing conditions, script adjustments, and validating the variable name are critical. Alternatively, using Client Scripts can provide a dynamic means to display the prefixed text immediately on the form.
Please let me know if you encounter specific error messages or behaviors, and we can troubleshoot further!
Save the Client Script.
Testing the Client Script
Submit a New Request:
Go to the Service Catalog and fill out the form.
Enter a value in your description field.
Check the RITM:
Once the request is submitted, navigate to the RITM and check the Variables section.
The description should be prefixed correctly as "PRE: ABC" (if you entered "ABC").
Using a Business Rule (If Still Desired)
If you prefer to keep using a Business Rule, make sure it is set to run on insert rather than after insert:
Navigate to Business Rules:
Go to System Definition > Business Rules.
Create a New Rule:
Create a new Business Rule or modify an existing one.
Business Rule Conditions:
Name: Set a name similar to “Prefix Description”.
Table: Set to Requested Item [sc_req_item].
When: Set to Before (not after).
Insert: Checked.
Update: Optional, based on your needs.
Script Section:
Use the same script as mentioned before (make sure to modify the variable name accordingly):
javascript
(function executeRule(current, previous /*null when async*/) {
// Variable name for the description variable
var descriptionVarName = 'description';
// Getting the value of the variable
var originalDescription = current.variables[descriptionVarName];
// Check if the variable is defined and has a value before modifying it
if (originalDescription) {
// Prefix it with "PRE: "
current.variables[descriptionVarName] = 'PRE: ' + originalDescription;
}
})(current, previous);
Save the Business Rule.
Summary
Using a Client Script to modify the user's input before submission is the most straightforward and effective method when dealing with Service Catalog variables. It allows real-time feedback and modifies values before they are saved to the database.
If you find that a Business Rule is still necessary for your logic, ensure it executes before insert rather than after.
Let me know if you encounter any specific issues or have further questions!
Sometimes, other Client Scripts might interfere with the execution. Check if there are any other scripts that might be overriding or conflicting with your changes.
Alternative: Using Business Rules
If you find that Client Scripts still aren't behaving as expected, consider relying on a Business Rule to make the adjustments (although they won't modify the display in real time like Client Scripts). However, it’s less flexible for immediate user feedback compared to the Client Script method.
Final Example of a Working onSubmit Script
Here is the complete script to confirm you have the right setup:
javascript
function onSubmit() {
// Access the description variable, ensure the name is correct
var descField = g_form.getValue('description'); // Use your actual variable name here
// Check for a non-empty value
if (descField) {
// Prefix the description with "PRE: "
g_form.setValue('description', 'PRE: ' + descField);
}
// Allow the form submission to continue
return true;
}
After Implementing Changes
Re-test the request submission in the Service Portal to see if the prefix appears on the RITM after this script executes.
If it still doesn't work, feel free to share the specific behavior you are observing, or details about how you are testing, and I can help you troubleshoot further.
Important Considerations
Context of Execution: Keep in mind that the Client Script on sc_req_item will be executed every time an RITM is loaded or submitted, so ensure you handle conditions accordingly to avoid unwanted changes.
Variable Accessibility:
Client Scripts are generally not intended for fields in the sc_req_item table unless they pertain to the specific form being used.
If you're manipulating variables that belong to specific catalog items, it's best to do so via Client Scripts associated with those catalog items instead.
Global vs. Item-Specific: If this field behavior needs to change based on the specific catalog item type rather than a global change for all RITMs, that logic should generally reside in an Item-level Client Script rather than a global sc_req_item script.
Testing the Client Script
Submit a New Request:
After saving the script, go to your Service Catalog, request the item associated with the script, fill in the description variable, and submit the request.
Verify the Result:
Check the Requested Item (RITM) to confirm if the description value has been prefixed correctly.
Conclusion
While it is technically possible to create Client Scripts on the sc_req_item table to modify variable values, the common practice is to utilize these scripts directly on catalog item forms to provide better control and more predictable behavior. Always ensure to test any changes made in a sub-production instance first to validate their impact and performance. Let me know if you need more information or assistance with a specific aspect of this process!
function onSubmit() {
// Replace 'description' with the correct name of your variable
var descVariableName = 'description'; // Ensure this matches your variable name
// Get the value of the description variable
var descriptionValue = g_form.getValue(descVariableName);
// Check if there is a value for the variable
if (descriptionValue) {
// Prefix the variable value with "PRE: "
g_form.setValue(descVariableName, 'PRE: ' + descriptionValue);
}
// Return true to allow submission to proceed
return true;
}
Step 3: Saving and Testing
Save the Client Script.
Submit a New Request:
Go to the Service Catalog, fill out the form for your catalog item, and leave a value in the description variable field.
Check the RITM:
Once you've submitted the request, navigate to the associated RITM and check the values of the variables. The description variable should now appear as "PRE: ABC" (if you entered "ABC").
Important Notes
Variable vs. Form Field: This script will only modify the variable value in your catalog item submission and will not affect the form-level "description" field on the RITM itself. If your RITM has a separate description field that you wish to modify, you'll likely need a separate Business Rule to handle that after the record has been inserted into the sc_req_item table.
Careful with Naming: Be cautious to ensure that the variable name (description in the script) matches exactly what you have in the catalog item definition regarding case-sensitivity.
Summary
This setup will allow you to prepend your value with "PRE: " on the variable description at the time of form submission. As a best practice, always test your scripts in a development or staging environment first to verify behavior before deploying to production. Please let me know if you need additional configuration or further assistance!
"PRE: ABC"
Important Notes
Conditions to Check
Variable Name: Ensure that the descVariableName in the script exactly matches the name of your description variable.
Prefix Check: The condition !descriptionValue.startsWith('PRE: ') is used to prevent appending the prefix if it’s already present, avoiding unnecessary changes if the form is reloaded.
Limitations
The onLoad script modifies the field whenever the RITM is opened. If the description is changed afterward, a similar approach should be taken to maintain the desired state.
This script affects all RITMs since it's applied at the sc_req_item level, so be cautious about unintended changes to other records if applicable.
Summary
By following these steps, you should successfully add a prefix to the description variable whenever the RITM form is loaded, enhancing clarity for users. If you have any further questions or need additional assistance, please let me know!