To check checkboxes based on field values

Poorva Bhawsar
Mega Sage

Hi Community,

 

When user selects some variables values as approved from the dropdowns on catalog task, i want to check some checkboxes on the cmdb_ci form.

For e.g., if xyz is selected as approved from the dropdown list, then it should check xyz checkbox on the cmdb_ci form before closing the request.

 

Thanks

1 ACCEPTED SOLUTION

Hi,

it was not working because you changed the variable names for GlideRecord (you were using 'grCI' it should be 'gr1')

Try below:

else if (current.variables.oat_type == 'Database') {

    var server = [];
    var mrvsParsed = JSON.parse(current.variables.doat_server_details.toString());
    for (var x in mrvsParsed) {
        server.push(mrvsParsed[x].server_name.toString());
    }
    //var server = current.variables.doat_server_details.server_name.toString();
    gs.log("OAT Type: Database, Server Name: " + server, "YourScriptName");
    workflow.info("OAT Type: Database, Server Name: " + server);
    var gr1 = new GlideRecord('cmdb_ci');
    //gr1.addQuery('name', server);
    gr1.addEncodedQuery('sys_idIN' + server.toString());
    gr1.query();
    while (gr1.next()) {
        if (current.variables.privilaged_account_onboarded_to_piam_confirmation_approval == 'accept') {
            //gr1.u_tpam == true;
            gr1.setValue('u_tpam', true);
        }
        if (current.variables.database_onboarded_to_siem_confirmation_approval == 'accept') {
            //gr1.u_siem == true;
            gr1.setValue('u_siem', true);
        }
        if (current.variables.cis_scan_nessus_scan_passed_confirmation_approval == 'accept') {
            //gr1.u_nessus == true;
            gr1.setValue('u_nessus', true);
        }
        if (current.variables.ds_am_av_and_network_protect_with_ips_policy_is_set_to_prevent_or_ms_defender_installed == 'accept') {
            //gr1.u_av_am_ips == true;
            //gr1.u_xdr == true;
            gr1.setValue('u_av_am_ips', true);
            gr1.setValue('u_xdr', true);
        }
            gr1.update();
            gs.log("Updated your_multiline_text_variable_set_table record for Database - Sys ID: " + gr1.sys_id, "YourScriptName");
            workflow.info("Updated your_multiline_text_variable_set_table record for Database - Sys ID: " + gr1.sys_id);
        }
    }

  

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

34 REPLIES 34

@Poorva Bhawsar 

Can you please share your latest script?

Also what logs you are getting?

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

if (current.variables.oat_type == 'Server') {
    gs.info('Inside Server condition');
    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 gr = new GlideRecord('cmdb_ci');
        //gr.addQuery('name', server_name);
        //gr.addEncodedQuery('sys_idIN' + server_name.toString());
        gr.addQuery('sys_id', arr[i]);
        gr.query();
        while (gr.next()) {
            if (current.variables.privilaged_account_onboarded_to_piam_confirmation_approval == 'accept') {
                gr.u_tpam == true;
            }
            if (current.variables.database_onboarded_to_siem_confirmation_approval == 'accept') {
                gr.u_siem == true;
            }
            if (current.variables.cis_scan_nessus_scan_passed_confirmation_approval == 'accept') {
                gr.u_nessus == true;
            }
            if (current.variables.ds_am_av_and_network_protect_with_ips_policy_is_set_to_prevent_or_ms_defender_installed == 'accept') {
                gr.u_av_am_ips == true;
                gr.u_xdr == true;
            }
        }
        gs.log("OAT Type: Server, Server Name: " + server_name, "YourScriptName");
        workflow.info("OAT Type: Server, Server Name: " + server_name);

        //gr.update();
        answer.push(gr.toString());
        gs.log("Updated cmdb_ci record for Server - Sys ID: " + gr.sys_id, "YourScriptName");
        workflow.info("Updated cmdb_ci record for Server - Sys ID: " + gr.sys_id);
    }
} else if (current.variables.oat_type == 'Database') {
    //var server = current.variables.server_name;
    var server = [];
    var mrvsParsed = JSON.parse(current.variables.doat_server_details.toString());
    for (var x in mrvsParsed) {
        server.push(mrvsParsed[x].server_name.toString());
    }
    gs.log("OAT Type: Database, Server Name: " + server, "YourScriptName");
    workflow.info("OAT Type: Database, Server Name: " + server);
    var gr1 = new GlideRecord('cmdb_ci');
    //gr1.addQuery('name', server);
    gr1.addEncodedQuery('sys_idIN' + server);
    gr1.query();
    if (gr1.next()) {
        if (current.variables.privilaged_account_onboarded_to_piam_confirmation_approval == 'accept') {
            gr1.u_tpam == true;
        }
        if (current.variables.database_onboarded_to_siem_confirmation_approval == 'accept') {
            gr1.u_siem == true;
        }
        if (current.variables.cis_scan_nessus_scan_passed_confirmation_approval == 'accept') {
            gr1.u_nessus == true;
        }
        if (current.variables.ds_am_av_and_network_protect_with_ips_policy_is_set_to_prevent_or_ms_defender_installed == 'accept') {
            gr1.u_av_am_ips == true;
            gr1.u_xdr == true;
        }
        gr1.update();
        gs.log("Updated your_multiline_text_variable_set_table record for Database - Sys ID: " + gr1.sys_id, "YourScriptName");
        workflow.info("Updated your_multiline_text_variable_set_table record for Database - Sys ID: " + gr1.sys_id);
    }
}

@Poorva Bhawsar Use below script as it is:

if (current.variables.oat_type == 'Server') {
    gs.info('Inside Server condition');
    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');       
        grCI.addEncodedQuery('sys_idIN' + server_name.toString());   
        grCI.query();
        while (grCI.next()) {
            if (current.variables.privilaged_account_onboarded_to_piam_confirmation_approval == 'accept') {
                grCI.u_tpam == true;
            }
            if (current.variables.database_onboarded_to_siem_confirmation_approval == 'accept') {
                grCI.u_siem == true;
            }
            if (current.variables.cis_scan_nessus_scan_passed_confirmation_approval == 'accept') {
                grCI.u_nessus == true;
            }
            if (current.variables.ds_am_av_and_network_protect_with_ips_policy_is_set_to_prevent_or_ms_defender_installed == 'accept') {
                grCI.u_av_am_ips == true;
                grCI.u_xdr == true;
            }
        }
        gs.log("OAT Type: Server, Server Name: " + server_name, "YourScriptName");
        workflow.info("OAT Type: Server, Server Name: " + server_name);

        grCI.update();
        answer.push(grCI.getUniqueValue());
        gs.log("Updated cmdb_ci record for Server - Sys ID: " + grCI.sys_id, "YourScriptName");
        workflow.info("Updated cmdb_ci record for Server - Sys ID: " + grCI.sys_id);
    }
} else if (current.variables.oat_type == 'Database') {
   
    var server = [];
    var mrvsParsed = JSON.parse(current.variables.doat_server_details.toString());
    for (var x in mrvsParsed) {
        server.push(mrvsParsed[x].server_name.toString());
    }
    gs.log("OAT Type: Database, Server Name: " + server, "YourScriptName");
    workflow.info("OAT Type: Database, Server Name: " + server);
    var gr1 = new GlideRecord('cmdb_ci');
    //gr1.addQuery('name', server);
    gr1.addEncodedQuery('sys_idIN' + server);
    gr1.query();
    while (gr1.next()) {
        if (current.variables.privilaged_account_onboarded_to_piam_confirmation_approval == 'accept') {
            gr1.u_tpam == true;
        }
        if (current.variables.database_onboarded_to_siem_confirmation_approval == 'accept') {
            gr1.u_siem == true;
        }
        if (current.variables.cis_scan_nessus_scan_passed_confirmation_approval == 'accept') {
            gr1.u_nessus == true;
        }
        if (current.variables.ds_am_av_and_network_protect_with_ips_policy_is_set_to_prevent_or_ms_defender_installed == 'accept') {
            gr1.u_av_am_ips == true;
            gr1.u_xdr == true;
        }
        gr1.update();
        gs.log("Updated your_multiline_text_variable_set_table record for Database - Sys ID: " + gr1.sys_id, "YourScriptName");
        workflow.info("Updated your_multiline_text_variable_set_table record for Database - Sys ID: " + gr1.sys_id);
    }
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

I am using exactly same script but in the logs i am getting 4 logs which are changing continuously may be because of the loop.

PoorvaBhawsar_0-1703150956055.png

If i will refresh logs then it will show another sys id at the top and the previous on is the next record.

PoorvaBhawsar_1-1703150998755.png

Its not checking the checkboxes on the cmdb_ci table records.

Poorva Bhawsar
Mega Sage

@Anil Lande  the script which you have shared is inserting 2 new records and ticking the checkboxes. For e.g., i have selected 2 cis from the list collector variable but its inserting 2 new records for one of the ci record. I just want to update in the current records for all the cis which i have selected in the list collector.