Inbound action script help for stripping only computer name

RudhraKAM
Tera Guru

Hello I need to create an Incident when an Email from xyz is being sent to servicenow , but email might have some computer names which I need to only get those names and set it in Description of Incident , 

Below is the email which we will get and we only want computer names under Problematic BCA clients . 

Thanks in advance 

 

RudhraKAM_0-1738174506132.png

 

 

9 REPLIES 9

@RudhraKAM  You can build regex here and use match() to retrieve the computer name data. 

 

Doc link for further details.

String.prototype.match() 

 

Thanks

Harsh

 

ChrisBurks
Giga Sage

What's the HTML structure behind the email and aside from the count of computer names that might appear is the structure consistent?

pratyusha11
Tera Contributor
function onLoad() {
setTimeout(function() {
var parentValue = g_form.getValue('task_number');

if (parentValue) {
var ga = new GlideAjax('GetChangeInfo');
ga.addParam('sysparm_name', 'getChangeDetails');
ga.addParam('sysparm_change_id', parentValue);
ga.getXMLAnswer(function(response) {
if (response) {
var obj = JSON.parse(response);
if (obj.is_chg) {
if (obj.short_description) {
g_form.setValue('short_description', obj.short_description);
}
if (obj.cmdb_ci) {
g_form.setValue('cmdb_ci', obj.cmdb_ci);
}
}
}
});
}
}, 10);
}

RudhraKAM
Tera Guru

(function executeRule(current, previous) {
// 1. Define the property name
var propertyName = 'wf.change.success.score.icon.visibility';

// 2. Get the comma-separated list of roles from the property
var requiredRoles = gs.getProperty(propertyName);

// 3. Set the default visibility to false
g_scratchpad.showButton = 'false';

// 4. Check if the property has a value (roles specified)
if (requiredRoles) {
// 5. Check if the current user has ANY of the required roles
// gs.hasRole() can take a comma-separated string of roles.
if (gs.hasRole(requiredRoles)) {
g_scratchpad.showButton = 'true';
}
}

})(current, previous);

RudhraKAM
Tera Guru

<g2:evaluate var="jvar_disable_click" jelly="true">
// ... (Keep existing variable declarations) ...
var isNewRecord = current.isNewRecord();
var isActiveRecord = current.active;
var flag = true;
var disableClick = false;
var hideSpan = "";
var cr_type = current.type;
// ... (Keep existing URL properties) ...

// Check change type
if(cr_type == 'normal' || cr_type == 'expedited' || cr_type == 'emergency') {
flag = true;
} else {
flag = false;
}

// -------------------------------------------------------------------
// **CORRECTED ROLE CHECKING LOGIC**
// -------------------------------------------------------------------
var rolesProperty = gs.getProperty('wf.change.success.score.icon.visibility');
var hasRequiredRole = false; // Default to false until a role is confirmed

if (rolesProperty) {
// Use gs.hasRole() directly with the comma-separated string from the property.
// gs.hasRole() efficiently checks if the current user has ANY role in the list.
if (gs.hasRole(rolesProperty)) {
hasRequiredRole = true;
}
} else {
// If the property is empty, assume button should be hidden (or visible, depending on requirement)
// I will assume if the property is empty, the button is hidden for safety.
hasRequiredRole = false;
}

// If the user does NOT have the required role, set flag to false
if (!hasRequiredRole) {
flag = false;
}
// -------------------------------------------------------------------

if (isNewRecord || !isActiveRecord || !flag) {
disableClick = true;
hideSpan = "hidden";
}

disableClick;
</g2:evaluate>