Query variables in incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 03:33 AM
Hi All,
A new field needs to be created on the incident table called as "Is the Incident Existing/New?" (Select box with Existing and New choices). This field needs to be filled automatically based on the below logic.
1. The incident needs to be raised using only - "Create New Incident" record producer.
2. If the location of the incident matches any existing Incident's location AND
3. If "Category" (Variable on "Create New Incident" record producer.) of the current raised incident matches any existing Incident's Category AND
4. If "Subcategory" (Variable on "Create New Incident" record producer.) of the current raised incident matches any existing Incident's Subcategory.
Then "Is the Incident Existing/New?" should set to Existing if the above conditions matches true and if it doesn't it should set to New.
Can any one please guide me on this.
TIA.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 06:20 AM
On change of subcategory field, you need to create a client script and call a script include(by passing location, category and subcategory) to fetch existing sys_id. if the returned value has sys_id, set the variable to 'Yes'. else set 'Is the Incident Existing/New?' variable value to 'No'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 03:59 PM
@Nagashree5 You utilise the Record Producer script field to check if the incident with the location, Category and subcateogry already exist within the Incident table. If it returns true, set the field to Existing else new.
Let me know if you need script for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 04:15 AM
Hi @Sandeep Rajput ,
Thanks for the response. I'm using the same logic and wrote the below code but it always going to else condition.
var gbsinc = new GlideRecord('incident');
gbsinc.addQuery('location', current.location);
gbsinc.query();
while (gbsinc.next()) {
var erpval = producer.erp_choice.getDisplayValue();
var subval = producer.sub_category_all;
var value = gbsinc.variables.erp_choice.getDisplayValue();
var subcat = gbsinc.variables.sub_category_all;
if ((erpval == value) && (subval == subcat)) {
current.u_incident_error = 'Existing';
} else {
current.u_incident_error = 'New';
}
}
The issue I'm facing here is , when I keep only one if condition that is erp == val, the code is working fine, if I add the subcategory condition, it is always going to else condition. When I kept logs and checked, for few incidents subcategory is coming as null or undefined (No mandate that subcategory is there for all the incidents since it is a non mandate field).
Please suggest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2023 07:55 AM
Hi @Nagashree5
Have you checked what type of value is being returned by the variable ? if its string or true/false kind of ? maybe the output type is not matching. Any logs you added to check the output ?
mark helpful if it has contributed in someway to your query 🙂
Thank you and best regards,
Anwesha