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-27-2023 04:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2023 04:53 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2023 05:07 AM - edited ‎09-27-2023 05:12 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2023 05:23 AM
@Vani14,
Please test with the above script in your business rule.
Thanks,
Anshul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2023 05:42 AM
@anshul_goyal its not working