Need to change location automatically based on short description
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2023 02:49 AM
we need to update location automatically based on short description.
ex: [S0009R01] we will get the short description like this, and we have same location 0009 is it possible to change automatically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2023 06:39 AM - edited ‎09-28-2023 06:42 AM
Hi @Anubhav24 ,
(function executeRule(current, previous) {
var shortDescription = current.short_description;
current.location = null; // Set it to null initially
if (shortDescription) {
var locationNumberMatch = shortDescription.match(/S(\d+)R/);
if (locationNumberMatch && locationNumberMatch.length > 1) {
var locationNumber = locationNumberMatch[1];
var locRef = new GlideRecord("cmn_location");
locRef.addQuery("number", locationNumber);
locRef.query();
if (locRef.next()) {
current.location = locRef.getUniqueValue();
}
else {
gs.info("Short description is empty.");
}
})(current, previous);
we are using this script but the thing is location name showing same for all incidents.