Need to change location automatically based on short description

Vani14
Tera Contributor

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.

15 REPLIES 15

Vani14
Tera Contributor

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.

Vani14_0-1695908256073.png