We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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

 

 

12 REPLIES 12

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>

RudhraKAM
Tera Guru

// Fix script: Populate blank fields in Planned Outage based on Acceptance Criteria

(function() {

var outageGR = new GlideRecord('change_outage');
outageGR.addQuery('type', 'planned'); // Only Planned Outages
outageGR.query();

while (outageGR.next()) {

// Skip if parent CR is missing
if (!outageGR.change_request)
continue;

var cr = outageGR.change_request.getRefRecord();

// AC3: Only update if Parent CR is ACTIVE
if (cr.state == 3 || cr.state == 4) {
// 3 = Closed, 4 = Cancelled (varies by instance)
continue;
}

var updated = false;

// AC1 + AC2: Populate fields only if blank
if (!outageGR.cmdb_ci) {
outageGR.cmdb_ci = cr.cmdb_ci; // Primary CI of CR
updated = true;
}

if (!outageGR.begin) {
outageGR.begin = cr.start_date; // Planned Start date of CR
updated = true;
}

if (!outageGR.end) {
outageGR.end = cr.end_date; // Planned End date of CR
updated = true;
}

if (updated) {
outageGR.update();

// AC4: Add work note to Parent CR
cr.work_notes = "Fix script: Planned Outage record '" + outageGR.number +
"' updated with mandatory fields.";
cr.update();
}
}

gs.print("Fix script completed successfully.");

})();

pratyusha11
Tera Contributor
var deactivationDateStr = gdtDeactivate.getLocalDate().toString(); 
// Format: YYYY-MM-DD — then reformat cleanly:

var dateRaw = gdtDeactivate.getDate(); // returns GlideDate
var monthNames = ['January','February','March','April','May','June',
                  'July','August','September','October','November','December'];

// Extract parts from GlideDateTime
var dtStr = gdtDeactivate.getValue(); // "YYYY-MM-DD HH:mm:ss"
var dateParts = dtStr.split(' ')[0].split('-');
var year  = dateParts[0];
var month = parseInt(dateParts[1], 10) - 1; // 0-indexed
var day   = parseInt(dateParts[2], 10);

var deactivationDateStr = monthNames[month] + ' ' + day + ', ' + year;