The CreatorCon Call for Content is officially open! Get started here.

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

Hi @anshul_goyal ,

 

format is the same but location number will change.

ex: short description is : S00010R01 and location number: M0001
short description is : S117310R01 and location number: M1173

@Vani14,

Use the below script in the before-business rule to achieve your functionality.

Script:
var shortDes ="S00010R01";
var number = shortDes.split("").splice(1,4).join(""); // 0001 or 1173
var locRef = new GlideRecord("cmn_location");
locRef.addEncodedQuery("nameLIKE"+number);
locRef.query();
if(locRef.next()) {
var locSysId = locRef.getUniqueValue();
}
You can set the "locSysId" variable on the required field.

I hope this will help you solve your problem. Please mark it as Accepted and Helpful.
Thanks and Regards,
Anshul

Hi @anshul_goyal ,

we wrote the script already but its not working could you please let me know 

 

(function executeRule(current, previous) {
// Get the short description from the incident
var shortDescription = current.short_description;

// Check if the short description contains a location number
if (shortDescription) {
// Use a regular expression to extract the location number
var locationNumberMatch = shortDescription.match(/S(\d+)R/);

// Check if a location number was found
if (locationNumberMatch && locationNumberMatch.length > 1) {
// The extracted location number is in the second element of the match array
var locationNumber = locationNumberMatch[1];

// Update the incident's location field with the extracted location number
current.location = locationNumber;
}
}
})(current, previous);

@Vani14

Please test with the above script in your business rule.

Thanks,
Anshul

@anshul_goyal  its not working