- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 02:27 PM
Hi Everyone,
Had a quick question to see if it is possible to convert an incident description text to specific variables on a catalog item assuming the ticket always comes in the same format.
Incident
Description Text:
Full Name : John Smith
Preferred Name : John
Start Date: 09/12/2024
Catalog Item:
John Smith to variable full_name
John to variable preferred_name
09/12/2024 to variable_date
Specifically looking for the dynamic text that will come after the full name, preferred name and start date and map them to the corresponding fields using an UI Action.
I have the convert to the request down, its just a matter of what to put in the script to convert the text to a variable.
Even if it shows as Preferred Name: John Smith that is fine also.
Thank You in advance
Aaron
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 07:45 AM
Thanks Everyone for the help. Was able to do this by doing the below. I added exceptions to the array as our name formats are very dynamic for some reason that we get from our onboarding team. Code might be a little messy but was able to get around 50 different test cases with it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 08:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 03:17 PM
To isolate each variable value you can split the incident description on ':', then you'll have an array of six members that you can trim and assign 1,3, and 5 to the respective variables in the Cart API or whatever you're using to create the Request.
var incDesArr = current.description.split(':');
var fname = incDesArr[1].trim();
var pname = incDesArr[3].trim();
var sdate = incDesArr[5].trim();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2024 12:52 AM
parseIncidentAndUpdateCatalogItem('incident_sys_id', 'catalog_item_sys_id');
function parseIncidentAndUpdateCatalogItem(incidentSysId, catalogItemSysId) {
// Initialize variables
var fullName = '';
var preferredName = '';
var startDate = '';
var grIncident = new GlideRecord('incident');
if (grIncident.get(incidentSysId)) {
var description = grIncident.getValue('description');
// Extract values using regex
var nameMatch = description.match(/Full Name\s*:\s*(.*)/);
var preferredNameMatch = description.match(/Preferred Name\s*:\s*(.*)/);
var startDateMatch = description.match(/Start Date\s*:\s*(.*)/);
if (nameMatch) {
fullName = nameMatch[1].trim();
}
if (preferredNameMatch) {
preferredName = preferredNameMatch[1].trim();
}
if (startDateMatch) {
startDate = startDateMatch[1].trim();
}
/
gs.info('Full Name: ' + fullName);
gs.info('Preferred Name: ' + preferredName);
gs.info('Start Date: ' + startDate);
var grCatalogItem = new GlideRecord('sc_req_item');
if (grCatalogItem.get(catalogItemSysId)) {
grCatalogItem.setValue('u_full_name', fullName); // Assuming custom field 'u_full_name' exists
grCatalogItem.setValue('u_preferred_name', preferredName); // Assuming custom field 'u_preferred_name' exists
grCatalogItem.setValue('u_date', startDate); // Assuming custom field 'u_date' exists
grCatalogItem.update();
} else {
gs.error('Catalog item not found: ' + catalogItemSysId);
}
} else {
gs.error('Incident not found: ' + incidentSysId);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 08:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 07:45 AM
Thanks Everyone for the help. Was able to do this by doing the below. I added exceptions to the array as our name formats are very dynamic for some reason that we get from our onboarding team. Code might be a little messy but was able to get around 50 different test cases with it.