Can any user create an incident using Virtual Agent or do they require a specific role to be able to (eg. itil)? in servicneow
Assistant
In ServiceNow, not every user can create an incident using the Virtual Agent by default. Typically, the ability to create incidents—whether through the Virtual Agent or directly in the Incident Management application—depends on the user's roles and the configurations in your instance.
User
Hello, I have the below multi row variable set. How can I have the "Total Weight" and "Total Price" automatically calculate once "Unit Weight" is populated.
"Total Weight" = "Quantity" x "Unit Weight"
"Total Price" = "Quantity" x "Unit Price"
Client script
Assistant
Key points:
Roles: Generally, users need the itil role to create incidents. The itil role grants permissions to create, read, update, and delete incident records.
Default Users: Users without the itil role usually cannot create or update incidents directly. However, some organizations configure ServiceNow so that end users (employees, customers) can submit incidents or requests without the itil role, often through a self-service portal or Virtual Agent.
Virtual Agent: The Virtual Agent behavior depends on how it is configured. If the Virtual Agent is set up to create incidents on behalf of the user, it uses predefined service accounts or integration users with proper roles (like itil) to perform these operations.
Impersonation: The Virtual Agent scripts or flows run with a specific user context or can impersonate a user with appropriate roles. This means that although the end user may not have incident creation rights, the bot can still create the incident record using a service account with itil role.
Configuration: The system administrator can configure Virtual Agent topics/workflows to allow users without the itil role to create incidents by leveraging service accounts or specially configured integration users.
Summary
End users typically do NOT need the itil role to create an incident via the Virtual Agent, because the bot is configured to create the incident using a user with the itil role behind the scenes.
If no special configuration exists, only users with itil (or equivalent) can create incident records.
To enable any user to create incidents through Virtual Agent, ensure the Virtual Agent's incident creation flow uses an integration user or service account with proper roles, allowing creation without exposing those permissions directly to the user.
If you want to enable this capability in your instance, verify the Virtual Agent incident creation flow and ensure it runs under a user with the necessary roles or configure the access control rules accordingly.
To automatically calculate Total Weight and Total Price based on the inputs in a Multi-Row Variable Set (MRVS) in ServiceNow, you typically use a Catalog Client Script (type: onChange or onLoad/onChange combination) targeting the multi-row variable.
However, because MRVS variables are rendered as multiple rows with sets of fields, handling events on them is a little different than standard form fields.
Scenario Recap:
Variables inside MRVS:
Quantity (number)
Unit Weight (number)
Total Weight (number, calculated)
Unit Price (number)
Total Price (number, calculated)
Formulas:
Total Weight = Quantity * Unit Weight
Total Price = Quantity * Unit Price
How to do it
Because MRVS creates multiple rows dynamically, the client script must:
Detect when Unit Weight or Unit Price or Quantity is changed in any row
Recalculate Total Weight or Total Price in the same row immediately
Sample Client Script (Catalog Client Script)
Type: onChange
Variable name: you can set this on Quantity, Unit Weight, Unit Price (or create separate onChange scripts on each). Alternatively, use a UI Script for the entire MRVS.
Applies to: the variable set (you can scope it per variable or for the whole MRVS)
Approach: Use a Catalog Client Script of type "onChange" on all related variables, or a Catalog Client Script of type "onLoad" that hooks change events for the MRVS fields.
Example: Catalog Client Script - onChange for relevant fields (Quantity, Unit Weight, Unit Price)
Because the MRVS fields' DOM ids have a special pattern, you can access them with g_form.getValue() and g_form.setValue() with the "variable name" and a row suffix.
For example:
For a variable called quantity inside MRVS named items, the ids could be like: ni.items.0.quantity ni.items.1.quantity
and so on.
A practical solution using Catalog Client Script (onChange)
js
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Variables are inside a multi-row variable set called: items
// Assuming variable names: quantity, unit_weight, unit_price, total_weight, total_price
// We want to get the current row being changed, parse it and update totals
// Get the triggering control ID
var variableName = g_form.getVariableNameFromElement(control);
// The control id for MRVS has a numeric row index suffix, e.g. items_0_unit_weight or similar
// Extract row index
// The variable name style can differ based on the platform version, let's detect the row index from the control's ID
var id = control.id;
// id example: 'IO:mrvs_variable_set_name:0:unit_weight' or 'ni.items_0_unit_weight' depending on version
// Create a regex to find the row index
var match = id.match(/(\d+)/);
if (!match) {
return;
}
var rowIndex = match[1];
// Prepare variable names with row index
function getVarName(baseName) {
return 'ni.your_mrvs_variable_set_name_' + rowIndex + '_' + baseName;
}
// You can use g_form.getValue but often it doesn't work for MRVS variables. Instead use jQuery to get values from inputs.
// Or better: use the new catalog client API (g_form.getValue) with MRVS syntax:
// 'variable_name' is: mrvsVariableName[rowIndex].variableName inside the data model
// But that is not always straightforward.
// For more generic approach, use jQuery selectors:
// Find quantity
var quantitySelector = '[name="ni.your_mrvs_variable_set_name.'+rowIndex+'.quantity"]';
var unitWeightSelector = '[name="ni.your_mrvs_variable_set_name.'+rowIndex+'.unit_weight"]';
var unitPriceSelector = '[name="ni.your_mrvs_variable_set_name.'+rowIndex+'.unit_price"]';
var totalWeightSelector= '[name="ni.your_mrvs_variable_set_name.'+rowIndex+'.total_weight"]';
var totalPriceSelector = '[name="ni.your_mrvs_variable_set_name.'+rowIndex+'.total_price"]';
var quantity = $(quantitySelector).val();
var unitWeight = $(unitWeightSelector).val();
var unitPrice = $(unitPriceSelector).val();
quantity = parseFloat(quantity) || 0;
unitWeight = parseFloat(unitWeight) || 0;
unitPrice = parseFloat(unitPrice) || 0;
var totalWeight = quantity * unitWeight;
var totalPrice = quantity * unitPrice;
// Set the total weight and total price values
// Note: total_weight and total_price are readonly fields populated by this script
$(totalWeightSelector).val(totalWeight.toFixed(2)).trigger('change');
$(totalPriceSelector).val(totalPrice.toFixed(2)).trigger('change');
}
Important Notes:
Replace your_mrvs_variable_set_name with the actual name of your Multi-Row Variable Set (check the variable set sys_name or the name in the catalog item variables).
If the above ni.your_mrvs_variable_set_name.rowIndex.variableName syntax doesn't work, you can inspect the HTML elements on the catalog item order form to get the exact input element names or IDs for the multi-row variables.
Alternative simpler approach (Common pattern used)
Here is a ready-to-use generic approach that works in many ServiceNow MRVS implementations:
js
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
var id = control.id;
var rowIdxMatch = id.match(/\d+/);
if (!rowIdxMatch)
return;
var idx = rowIdxMatch[0];
// Change variable names accordingly to your MRVS variable names
var quantity = g_form.getValue('quantity' + idx) || 0;
var unit_weight = g_form.getValue('unit_weight' + idx) || 0;
var unit_price = g_form.getValue('unit_price' + idx) || 0;
quantity = parseFloat(quantity);
unit_weight = parseFloat(unit_weight);
unit_price = parseFloat(unit_price);
var total_weight = (quantity * unit_weight).toFixed(2);
var total_price = (quantity * unit_price).toFixed(2);
g_form.setValue('total_weight' + idx, total_weight);
g_form.setValue('total_price' + idx, total_price);
}
But unfortunately, out-of-the-box g_form.getValue and setValue do not consistently work for MRVS inputs as they do for standard variables.
Recommended: Use Catalog Client Script of type onChange on each of the fields Quantity, Unit Weight, Unit Price with the following snippet:
js
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '')
return;
// Parse the row index from control id
var id = control.id;
var rowIndexMatch = id.match(/\d+/);
if (!rowIndexMatch)
return;
var rowIndex = rowIndexMatch[0];
// Build input IDs in MRVS format
// Usually: ni.mrvsName.rowIndex.variableName
var baseName = 'ni.your_mrvs_name.' + rowIndex + '.';
var quantity = $('[name="' + baseName + 'quantity"]').val() || 0;
var unitWeight = $('[name="' + baseName + 'unit_weight"]').val() || 0;
var unitPrice = $('[name="' + baseName + 'unit_price"]').val() || 0;
quantity = parseFloat(quantity);
unitWeight = parseFloat(unitWeight);
unitPrice = parseFloat(unitPrice);
var totalWeight = (quantity * unitWeight).toFixed(2);
var totalPrice = (quantity * unitPrice).toFixed(2);
$('[name="' + baseName + 'total_weight"]').val(totalWeight).trigger('change');
$('[name="' + baseName + 'total_price"]').val(totalPrice).trigger('change');
}
Summary
Create one Catalog Client Script per variable you want to watch (quantity, unit_weight, unit_price), all running the same logic above.
Replace 'your_mrvs_name' with your MRVS variable set name. You can find this by inspecting the input names on the form.
The script parses the changed row index from the element ID, takes the values from Quantity, Unit Weight, and Unit Price for the same row, multiplies them, and updates Total Weight and Total Price fields.
If you want, I can help you with a tested complete example if you share your exact variable set names or the IDs shown in the DOM on your catalog item form.