Run script updating a field 2 times
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 11:22 PM
Hi Community,
A run script is updating a field 2 times.
Here is the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 11:40 PM
Does it update the same information several times, or does it update from different 'if' statements?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 12:04 AM
It updates all the if conditions 2 times.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 12:25 AM - edited 02-08-2024 12:33 AM
Can you start with the first 'if', make the other's 'else if' and end with an 'else' by setting your first line (the one above your first if: "grCI.u_deviation_notes = "Request Number: " + current.number + " - Cerification Notes" + "\n";"
//get sctask number
var sctnum = '';
var sct = new GlideRecord('sc_task');
sct.addQuery('request_item', current.sys_id);
sct.query();
if (sct.next()) {
sctnum = sct.number;
}
if (current.variables.oat_type == 'Server') {
var answer = [];
var server_name = current.variables.server_name_s.toString();
var arr = server_name.split(',');
for (var i = 0; i < arr.length; ++i) {
var grCI = new GlideRecord('cmdb_ci_server');
grCI.addEncodedQuery('sys_idIN' + server_name.toString());
grCI.query();
while (grCI.next()) {
if (current.variables.vendor_support_in_place_approval == 'failed' || current.variables.vendor_support_in_place_approval == 'deviation/exemption provided' && current.variables.rejection_reason1 != '') {
grCI.u_deviation_notes = "Vendor Support Approval: " + current.variables.vendor_support_in_place_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason1 + "\n";
}
else if (current.variables.built_as_per_soe_approval == 'failed' || current.variables.built_as_per_soe_approval == 'deviation/exemption provided' && current.variables.rejection_reason3 != '') {
grCI.u_deviation_notes = "Built as per SOE Approval: " + current.variables.built_as_per_soe_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason3 + "\n";
}
else if (current.variables.infra_design_document_isc_isd_approval == 'failed' || current.variables.infra_design_document_isc_isd_approval == 'deviation/exemption provided' && current.variables.rejection_reason5 != '') {
grCI.u_deviation_notes = "Infra Design ISC/ISD Approval: " + current.variables.infra_design_document_isc_isd_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason5 + "\n";
}
else if (current.variables.db_monitoring_tested_approval == 'failed' || current.variables.db_monitoring_tested_approval == 'deviation/exemption provided' && current.variables.rejection_reason7 != '') {
grCI.u_deviation_notes = "Monitoring Tested Approval: " + current.variables.db_monitoring_tested_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason7 + "\n";
}
else if (current.variables.shutdown_started_tested_approval == 'failed' || current.variables.shutdown_started_tested_approval == 'deviation/exemption provided' && current.variables.rejection_reason9 != '') {
grCI.u_deviation_notes = "Shutdown Started Tested Approval: " + current.variables.shutdown_started_tested_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason9 + "\n";
}
else if (current.variables.version_is_atleast_tweleve_month_from_vendor_eos_approval == 'failed' || current.variables.version_is_atleast_tweleve_month_from_vendor_eos_approval == 'deviation/exemption provided' && current.variables.rejection_reason2 != '') {
grCI.u_deviation_notes = "Version 12 months old from EOS Approval: " + current.variables.version_is_atleast_tweleve_month_from_vendor_eos_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason2 + "\n";
}
else if (current.variables.pre_doat_checklist_approval == 'failed' || current.variables.pre_doat_checklist_approval == 'deviation/exemption provided' && current.variables.rejection_reason4 != '') {
grCI.u_deviation_notes = "Pre DOAT Checklist Approval: " + current.variables.pre_doat_checklist_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason4 + "\n";
}
else if (current.variables.built_as_per_design_approval == 'failed' || current.variables.built_as_per_design_approval == 'deviation/exemption provided' && current.variables.rejection_reason8 != '') {
grCI.u_deviation_notes = "Built as per Design Approval: " + current.variables.built_as_per_design_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason8 + "\n";
}
else if (current.variables.backup_restore_tested_approval == 'failed' || current.variables.backup_restore_tested_approval == 'deviation/exemption provided' && current.variables.rejection_reason6 != '') {
grCI.u_deviation_notes = "Back-up/Restore Tested Approval: " + current.variables.backup_restore_tested_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason6 + "\n";
}
else if (current.variables.non_prod_oat_is_passed_approval == 'failed' || current.variables.non_prod_oat_is_passed_approval == 'deviation/exemption provided' && current.variables.rejection_reason11 != '') {
grCI.u_deviation_notes = "Non-Prod OAT passed Approval: " + current.variables.non_prod_oat_is_passed_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason11 + "\n";
}
else if (current.variables.csrc_patching_cadence == 'failed' || current.variables.csrc_patching_cadence == 'deviation/exemption provided' && current.variables.sr_rejection_reason2 != '') {
grCI.u_deviation_notes = "CSRC Patching Approval: " + current.variables.csrc_patching_cadence + " - " + "Rejected/Deviation Reason: " + current.variables.sr_rejection_reason2 + "\n";
}
else if (current.variables.database_onboarded_to_siem_confirmation_approval == 'failed' || current.variables.database_onboarded_to_siem_confirmation_approval == 'deviation/exemption provided' && current.variables.sr_rejection_reason3 != '') {
grCI.u_deviation_notes = "DB Onboarded to SIEM Approval: " + current.variables.database_onboarded_to_siem_confirmation_approval + " - " + "Rejected/Deviation Reason: " + current.variables.sr_rejection_reason3 + "\n";
}
else if (current.variables.server_privilaged_account_onboarded_to_piam == 'failed' || current.variables.server_privilaged_account_onboarded_to_piam == 'deviation/exemption provided' && current.variables.sr_rejection_reason1 != '') {
grCI.u_deviation_notes = "Server Privilege Account Onboarded to PIAM Approval: " + current.variables.server_privilaged_account_onboarded_to_piam + " - " + "Rejected/Deviation Reason: " + current.variables.sr_rejection_reason1 + "\n";
}
else if (current.variables.privilaged_account_onboarded_to_piam_confirmation_approval == 'failed' || current.variables.privilaged_account_onboarded_to_piam_confirmation_approval == 'deviation/exemption provided' && current.variables.sr_rejection_reason4 != '') {
grCI.u_deviation_notes = "Privilege Account Onboarded to PIAM Approval: " + current.variables.privilaged_account_onboarded_to_piam_confirmation_approval + " - " + "Rejected/Deviation Reason: " + current.variables.sr_rejection_reason4 + "\n";
}
else if (current.variables.account_management_onboarded_to_uam_approval == 'failed' || current.variables.account_management_onboarded_to_uam_approval == 'deviation/exemption provided' && current.variables.sr_rejection_reason5 != '') {
grCI.u_deviation_notes = "Account Management Onboarded to UAM Approval: " + current.variables.account_management_onboarded_to_uam_approval + " - " + "Rejected/Deviation Reason: " + current.variables.sr_rejection_reason5 + "\n";
}
else if (current.variables.cis_scan_nessus_scan_passed_confirmation_approval == 'failed' || current.variables.cis_scan_nessus_scan_passed_confirmation_approval == 'deviation/exemption provided' && current.variables.sr_rejection_reason6 != '') {
grCI.u_deviation_notes = "CIS Scan Nessus Approval: " + current.variables.cis_scan_nessus_scan_passed_confirmation_approval + " - " + "Rejected/Deviation Reason: " + current.variables.sr_rejection_reason6 + "\n";
}
else if (current.variables.ds_am_av_and_network_protect_with_ips_policy_is_set_to_prevent_or_ms_defender_installed == 'failed' || current.variables.ds_am_av_and_network_protect_with_ips_policy_is_set_to_prevent_or_ms_defender_installed == 'deviation/exemption provided' && current.variables.sr_rejection_reason7 != '') {
grCI.u_deviation_notes = "DS AM/AV and Network Protect OR MS Defender installed Approval: " + current.variables.ds_am_av_and_network_protect_with_ips_policy_is_set_to_prevent_or_ms_defender_installed + " - " + "Rejected/Deviation Reason: " + current.variables.sr_rejection_reason7 + "\n";
}
else {
grCI.u_deviation_notes = "Request Number: " + current.number + " - Cerification Notes" + "\n";
}
grCI.update();
}
}
}
var app_name = current.variables.application_name.toString();
var grBusApp = new GlideRecord('cmdb_ci_business_app');
grBusApp.addEncodedQuery('sys_idIN' + app_name.toString());
grBusApp.query();
while (grBusApp.next()) {
grBusApp.u_deviation_notes = "Request Number: " + current.number + " - Task Number: " + sctnum + "\n" + "Certified :" + current.variables.oat_type;
grBusApp.update();
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 01:19 AM
Modified the encoded query and it worked perfectly fine.
grCI.addEncodedQuery('sys_idIN' + arr[i]);
