Run script updating a field 2 times

Poorva Bhawsar
Mega Sage

Hi Community,

 

A run script is updating a field 2 times.

 

Here is the code.

 

//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()) {
            //gs.log("Inside the loop");
            grCI.u_deviation_notes = "Request Number: " + current.number + " - Cerification Notes" + "\n";
            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.rejection_reason1 + "\n" + "Failed :" + current.variables.vendor_support_in_place_approval;
                grCI.u_deviation_notes = "Vendor Support Approval: " + current.variables.vendor_support_in_place_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason1 + "\n";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.rejection_reason3 + "\n" + "Failed :" + current.variables.built_as_per_soe_approval;
                grCI.u_deviation_notes = "Built as per SOE Approval: " + current.variables.built_as_per_soe_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason3 + "\n";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.rejection_reason5 + "\n" + "Failed :" + current.variables.infra_design_document_isc_isd_approval;
                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";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.rejection_reason7 + "\n" + "Failed :" + current.variables.db_monitoring_tested_approval;
                grCI.u_deviation_notes = "Monitoring Tested Approval: " + current.variables.db_monitoring_tested_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason7 + "\n";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.rejection_reason9 + "\n" + "Failed :" + current.variables.shutdown_started_tested_approval;
                grCI.u_deviation_notes = "Shutdown Started Tested Approval: " + current.variables.shutdown_started_tested_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason9 + "\n";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.rejection_reason2 + "\n" + "Failed :" + current.variables.version_is_atleast_tweleve_month_from_vendor_eos_approval;
                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";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.rejection_reason4 + "\n" + "Failed :" + current.variables.pre_doat_checklist_approval;
                grCI.u_deviation_notes = "Pre DOAT Checklist Approval: " + current.variables.pre_doat_checklist_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason4 + "\n";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.rejection_reason8 + "\n" + "Failed :" + current.variables.built_as_per_design_approval;
                grCI.u_deviation_notes = "Built as per Design Approval: " + current.variables.built_as_per_design_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason8 + "\n";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.rejection_reason6 + "\n" + "Failed :" + current.variables.backup_restore_tested_approval;
                grCI.u_deviation_notes = "Back-up/Restore Tested Approval: " + current.variables.backup_restore_tested_approval + " - " + "Rejected/Deviation Reason: " + current.variables.rejection_reason6 + "\n";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.rejection_reason11 + "\n" + "Failed :" + current.variables.non_prod_oat_is_passed_approval;
                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";
            }

            if (current.variables.csrc_patching_cadence == 'failed' || current.variables.csrc_patching_cadence == 'deviation/exemption provided' && current.variables.sr_rejection_reason2 != '') {
                //grCI.u_deviation_notes = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.sr_rejection_reason2 + "\n" + "Failed :" + current.variables.csrc_patching_cadence;
                grCI.u_deviation_notes = "CSRC Patching Approval: " + current.variables.csrc_patching_cadence + " - " + "Rejected/Deviation Reason: " + current.variables.sr_rejection_reason2 + "\n";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.sr_rejection_reason3 + "\n" + "Failed :" + current.variables.database_onboarded_to_siem_confirmation_approval;
                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";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.sr_rejection_reason1 + "\n" + "Failed :" + current.variables.server_privilaged_account_onboarded_to_piam;
                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";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.sr_rejection_reason4 + "\n" + "Failed :" + current.variables.server_privilaged_account_onboarded_to_piam;
                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";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.sr_rejection_reason5 + "\n" + "Failed :" + current.variables.account_management_onboarded_to_uam_approval;
                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";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.sr_rejection_reason6 + "\n" + "Failed :" + current.variables.cis_scan_nessus_scan_passed_confirmation_approval;
                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";
            }

            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 = "Request Number: " + current.number + " - Rejected/Deviation Reason :" + current.variables.sr_rejection_reason7 + "\n" + "Failed :" + current.variables.ds_am_av_and_network_protect_with_ips_policy_is_set_to_prevent_or_ms_defender_installed;
                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";
            }
            grCI.update();
        }
    }
}

var app_name = current.variables.application_name.toString();
var gr = new GlideRecord('cmdb_ci_business_app');
gr.addEncodedQuery('sys_idIN' + app_name.toString());
gr.query();
while (gr.next()) {
    gr.u_deviation_notes = "Request Number: " + current.number + " - Task Number: " + sctnum + "\n" + "Certified :" + current.variables.oat_type;

    gr.update();
}
 
The bold part of the code is updating deviation notes field 2 times in the server table. Other part of the code is working perfectly fine.
8 REPLIES 8

Mohith Devatte
Tera Sage
Tera Sage

@Poorva Bhawsar I think as per your code there is a chance that it might satisfy multiple IF statements which can update twice.

 

Please check if its updating different info which can be other if statement also 

 

Hope this helps 

Mark the answer correct if this helps you 

Thanks

All the if conditions are separate and all are updating twice if all satisfies.

@Poorva Bhawsar can you please try this in your code in the above part of the code instead of 

 

 var server_name = current.variables.server_name_s.toString();
    var arr = server_name.split(',');
 
Try this 
 
    var arr =current.variables.server_name_s.toString().split(',');

Modified the encoded query grCI.addEncodedQuery('sys_idIN' + arr[i]); and it worked fine.