Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

Hi @Poorva Bhawsar no need to do multiple glide, you can just pass multiple variables like this

 

gr.comments += "Rejected Reason :"+current.variables.variablename +'<br>'+ "Reason": +current.fieldname +'<br>'+ "variableName:"+current.variables.variablename +'<br>'+;

gr.comments += variableName1:"+current.variables.variablename1 +'<br>'+;

gr.comments += variableName2:"+current.variables.variablename2 +'<br>'+;,

 

it will map all your variables to comments field. you can see the mapped values in activity of the record .

Regards
Harish

But i have multiple variables and for those multiple variables i have multiple different variables for rejection reasons.

//var reqtask = new GlideRecord("sc_task");
//reqtask.addQuery('request_item', reqitem.sys_id);
//reqtask.query();
//while (reqtask.next()) {
    if (current.variables.vendor_support_in_place_approval == 'failed' && current.variables.rejection_reason3 != ''){
        var gr = new GlideRecord('sc_task');
        gr.addQuery('parent', current.sys_id);
        gr.query();
        if(gr.next()){
            gr.u_deviation_notes = "Requested Number: " + current.variables.number, "Rejected Reason :" + current.variables.rejection_reason3 +'<br>'+ "Failed :" + current.vendor_support_in_place_approval;
        }

    }
       
    if (current.variables.built_as_per_soe_approval == 'failed' && current.variables.rejection_reason1 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.infra_design_document_isc_isd_approval == 'failed' && current.variables.rejection_reason5 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.db_monitoring_tested_approval == 'failed' && current.variables.rejection_reason7 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.shutdown_started_tested_approval == 'failed' && current.variables.rejection_reason9 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.version_is_atleast_tweleve_month_from_vendor_eos_approval == 'failed' && current.variables.rejection_reason2 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.pre_doat_checklist_approval == 'failed' && current.variables.rejection_reason4 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.built_as_per_design_approval == 'failed' && current.variables.rejection_reason8 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.backup_restore_tested_approval == 'failed' && current.variables.rejection_reason6 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.non_prod_oat_is_passed_approval == 'failed' && current.variables.rejection_reason11 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.patching_automated_approval == 'failed' && current.variables.rejection_reason10 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.csrc_patching_cadence == 'failed' && current.variables.sr_rejection_reason2 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.database_onboarded_to_siem_confirmation_approval == 'failed' && current.variables.sr_rejection_reason3 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.server_privilaged_account_onboarded_to_piam == 'failed' && current.variables.sr_rejection_reason4 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.account_management_onboarded_to_uam_approval == 'failed' && current.variables.sr_rejection_reason5 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.cis_scan_nessus_scan_passed_confirmation_approval == 'failed' && current.variables.sr_rejection_reason6 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;
    if (current.variables.ds_am_av_and_network_protect_with_ips_policy_is_set_to_prevent_or_ms_defender_installed == 'failed' && current.variables.sr_rejection_reason7 != '')
        reqtask.u_deviation_notes = "Requested Number: " + current.variables.number;

}
 
Like this. But its not working. So, do i need to gliderecord for all variables?

Hi @Poorva Bhawsar Assuming you BR is after update on SC Task table, try below code

 

if (current.variables.vendor_support_in_place_approval == 'failed' && current.variables.rejection_reason3 != ''){
var gr = new GlideRecord('tablename'); //table you want to copy variable value
gr.addQuery('parent', current.sys_id); // parent field from your table holds sc task sysID
gr.query();
if(gr.next()){
gr.u_deviation_notes = "Requested Number: " + current.variables.number, "Rejected Reason :" + current.variables.rejection_reason3 +'<br>'+ "Failed :" + current.vendor_support_in_place_approval;
gr.update(); // missed update here, you need to update your custom table
}

}

Regards
Harish

Do i need to glide record all conditions?