Copy Reference Value

Michael94
Tera Contributor

I am trying to print the number of a case from a variable. 

 

 

var gr_questions = new GlideRecord('question_answer');
gr_questions.addQuery('table_sys_id', current.sys_id);
gr_questions.query();
while (gr_questions.next()) {
// detemine the variable by its sys_id
if(question =='edb8224993798a5cffcdbac86cba1e34') {
var rQuestion = gr_questions.getDisplayValue('question');
var rAnswer = gr_questions.getDisplayValue('value');
if(rAnswer!="") {
var rCase = new GlideRecord('sn_hr_core_case');
if(rCase.get(rAnswer));{
//print the variable and its value in the description
desc.push(rQuestion + " " + rCase.getValue('number')); 
 }		
}
}

 

 

  

5 REPLIES 5

James Chun
Kilo Patron

Hi @Michael94,

 

Looks like a small mistake in one of the IF statements, instead of:

if(question =='edb8224993798a5cffcdbac86cba1e34') {

try the following:

    if (gr_questions.getValue('question') == 'edb8224993798a5cffcdbac86cba1e34') {

 

Cheers

Thanks James, but it is still not working. 

Is the above the entire script or a section of it?

Also, which application scope is this Business Rule created in?

It might be related to cross scope issue because you are accessing the [sn_hr_core_case] table.

Maddysunil
Kilo Sage

@Michael94 

  1. In your code, question seems to be undefined. You should either define it or use gr_questions.getValue('question') to get the value from the GlideRecord.

  2. There's a typo in your if condition: if(rCase.get(rAnswer));{. Remove the semicolon after if(rCase.get(rAnswer)) because it terminates the if statement prematurely.

Try with below updated code:

 

var desc = []; // Assuming desc is defined elsewhere in your script

var gr_questions = new GlideRecord('question_answer');
gr_questions.addQuery('table_sys_id', current.sys_id);
gr_questions.query();

while (gr_questions.next()) {
    // Get the value of the question field
    var question = gr_questions.getValue('question');

    // Determine the variable by its sys_id
    if (question == 'edb8224993798a5cffcdbac86cba1e34') {
        var rQuestion = gr_questions.getDisplayValue('question');
        var rAnswer = gr_questions.getDisplayValue('value');
        
        if (rAnswer != "") {
            var rCase = new GlideRecord('sn_hr_core_case');
            
            if (rCase.get(rAnswer)) {
                // Print the variable and its value in the description
                desc.push(rQuestion + " " + rCase.getValue('number')); 
            }
        }
    }
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks