Not able to query the 'Item Produced Records (sc_item_produced_record)' table in Script include.

Pallavi_G
Tera Expert

I am trying to query the table 'Item Produced Records (sc_item_produced_record)' in script include. I want the record producer name from the incident sysid. I wrote the below code. Here 'case_numb' is having incident sysid. But it is not going inside if loop.

Pallavi_G_0-1729682671830.png

 

But if i am hardcoding the sysid it is working fine

Pallavi_G_1-1729683058029.png

 

Can anyone help in it.

 

Thanks is Advance

 

8 REPLIES 8

Could you share the entire script, in case that helps show what is going on?

Below is the script 
 
getVariablesforPTR: function(case_numb) {
        try {
            var variableData = {};
            var desc = '';
            var catalog_name;
            var qa = new GlideRecord('question_answer');
            qa.addQuery('table_sys_id', case_numb);
            qa.orderBy('order');
            qa.query();
            while (qa.next()) {
                var variableValue = qa.value.getDisplayValue();

                if (variableValue != '' && ((qa.question.type == '8') || (qa.question.type == '31'))) {

                    //If question type is 8, it is a reference variable. Get the display value from target table
                    var ref = new GlideRecord(qa.question.reference);
                    if (ref.get(variableValue)) {
                        variableValue = ref.getDisplayValue();
                    }
                }

                if (variableValue != '' && (qa.question.type == '3' || qa.question.type == '5')) {
                    //If question type is 3 or 5, it is a choice variable or selectbox. Get the label from the question_choice table.
                    var ch = new GlideRecord('question_choice');
                    ch.addQuery('question', qa.getValue('question'));
                    ch.addQuery('value', qa.getValue('value'));
                    ch.query();
                    if (ch.next()) {
                        variableValue = ch.getValue('text');

                    }
                }

                if (variableValue == 'false' && (qa.question.type == '7' || qa.question.type == '11')) { //For checkbox, exclude values unchecked
                    variableValue = '';
                }

                if (qa.question.type == '11' && variableValue != '') { // Print Label
                    desc += qa.question.getDisplayValue() + "\n";

                } else if (qa.question.type == '7' && variableValue != '') // Print Checkboxes
                {
                    desc += qa.question.getDisplayValue() + " : " + variableValue + "\n\n";

                } else if (variableValue != '') {
                    if (qa.question.cat_item.getDisplayValue() == 'Revenue Accounting' && qa.question.getDisplayValue() == 'Seach Recommendation') {

                    } else {

                        desc += qa.question.getDisplayValue() + " : " + variableValue + "\n\n";

                    }
                }
            }

            gs.info('Final descr Name if numbers ' +  case_numb);

            var item_name = new GlideRecord('sc_item_produced_record');
            item_name.addQuery('task', case_numb);
            item_name.query();

            if (item_name.next()) {
                gs.info('Final descr Name inside if');
                catalog_name = item_name.producer.getDisplayValue();
                gs.info('Final descr Name ' + catalog_name);

            }

            gs.info('Final descr ' + 'Catalog item: ' + catalog_name + '\n' + desc);
            variableData.fieldDetails = 'Catalog item: ' + catalog_name + '\n' + desc;


            return variableData;

        }
 
In the first Gliderecord i am fetching the variable values for the particular Incident (Created from a record producer) which is working fine and in the second Gliderecord i am trying to fetch the Name of that record producer.

The only thing I see is that you have a try block without a catch, which probably isn't causing trouble, but it's also not doing anything to have this in a try block, so try it without.  Also, if you haven't, try with a hard-coded sys_id as a string value in place of case_numb to make sure this Script Include can query that table.  Since the two GlideRecords are not related, you could also try putting this one first.  Again, shouldn't matter, but something is holding this up.

I have added the catch block as well in my script just i did not mentioned here in the post. And i have tried using the hard coded sys_id in place of case_numb and it worked with it.