Copy Reference Value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 01:06 PM - edited 04-25-2024 11:17 AM
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'));
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 02:01 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 04:09 PM
Thanks James, but it is still not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 04:38 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 08:16 PM
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.
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