To copy variable's value into a journal type field

Poorva Bhawsar
Mega Sage

Hi Community,

 

I have few select box variables, if user selects the value of those variables as rejected, rejection reason field will populate. I want to copy the value of those variables if they are rejected along with the rejection reason from sctask to another table's journal type field.

 

I am thinking about the logic like if xyz == rejected && rejection reason != '' then need to add them in that journal field. If those are not rejected, those i approved i dont want to add them in this journal field.

 

Thanks,

Poorva Bhawsar

 

1 ACCEPTED SOLUTION

Hi @Poorva Bhawsar the error is below

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());//replace to arr[i]

to

grCI.addEncodedQuery('sys_idIN' + arr[i]);
grCI.query();
while (grCI.next()) {
//gs.log("Inside the l

Regards
Harish

View solution in original post

35 REPLIES 35

I have an issue here. Its updating deviation notes field twice.

 

//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();
}

Hi @Poorva Bhawsar can you share the comments screenshot to understand better? I can see your not concateting comments with += like below bold one

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";

Regards
Harish

I have added += previously but it was not working.

 

Here is the screenshot.

 

PoorvaBhawsar_0-1707377114060.png

 

Hi @Poorva Bhawsar there are two updates happening in your BR. can you put log  as per below

gs.info("script 1st update");

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()) {
gs.info("script 2nd update");
gr.u_deviation_notes = "Request Number: " + current.number + " - Task Number: " + sctnum + "\n" + "Certified :" + current.variables.oat_type;

gr.update();
}

Regards
Harish

2nd update is working perfectly fine. I have issue with the server part (first update).