The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Dynamic Content for dashboard

aditya174
Tera Guru

What is wrong with this piece of code is not able to get the value but it's working in the background script:

	var params = [];
			var tabName = 'task';
var tu = new TableUtils(tabName);
var list=[];
list.push(tu.getAllExtensions());
var c=0;
var count = 0;
for(var i=0;i <list.length;10;i++){
    var value=list[i];
    var gr = new GlideRecord('sys_dictionary');
    gr.addQuery('elementSTARTSWITHu_^ORelementSTARTSWITHx_')
    gr.addQuery('name', value);
    gr.query();
    while(gr.next()){
	<!-- params.push(gr.getValue('sys_id')); -->
        c+=1;
        <!-- gs.info(gr.getDisplayValue()+" "+ gr.name.getDisplayValue()); -->

        var grrr= new GlideRecord(gr.name.toString());
        grrr.query();
        var tot= grrr.getRowCount().toString();
        grrr.addQuery(gr.element ,"!=",'');
        grrr.query();
        <!-- gs.info("line 21:  "+tot+" "+ grrr.getRowCount()); -->
        var grtot = grrr.getRowCount();
        if(tot==grtot){
            count+=1;
            <!-- gs.info("line 24:  "+tot+" "+ grrr.getRowCount()); -->
             <!-- gs.info("empty fields: "+gr.getDisplayValue()+" "+ gr.name.getDisplayValue()); -->
        }

    }
}	
	
		params.push(c);
		params.push(count);
		params;		

 

 

2 REPLIES 2

Kartik Magadum
Kilo Sage

Hello @aditya174 

 

May be There are a few issues in your code that could be preventing it from working as expected:

  1. Syntax Errors: Your for loop syntax is incorrect. You are using &lt; instead of <, and the loop condition should be i < list.length; 10 should be replaced with i < list.length. The number 10 is not a valid condition for the loop.

  2. Comments within Code: You have commented out some code using HTML comment syntax (<!-- ... -->). In JavaScript, you should use // for single-line comments and /* ... */ for multi-line comments. The HTML-style comments may cause issues in your code execution.

  3. Query Conditions: In the gr.addQuery('elementSTARTSWITHu_^ORelementSTARTSWITHx_') line, it appears that you are trying to add two conditions. However, the way you've written it combines both conditions as a single string. You should use addQueryOr or addOrCondition to create an OR condition.

Please try below code

 

 

var params = [];
var tabName = 'task';
var tu = new TableUtils(tabName);
var list = [];
list.push(tu.getAllExtensions());
var c = 0;
var count = 0;

for (var i = 0; i < list.length; i++) {
    var value = list[i];
    var gr = new GlideRecord('sys_dictionary');
    gr.addQuery('elementSTARTSWITHu_^ORelementSTARTSWITHx_'); // Use OR condition
    gr.addQuery('name', value);
    gr.query();

    while (gr.next()) {
        c += 1;
        var grrr = new GlideRecord(gr.name.toString());
        grrr.query();
        var tot = grrr.getRowCount().toString();
        grrr.addQuery(gr.element, '!=', '');
        grrr.query();

        var grtot = grrr.getRowCount();
        if (tot == grtot) {
            count += 1;
            // Add your desired actions here
        }
    }
}

params.push(c);
params.push(count);
params;

 

 

 

Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Thanks & Regards,

Kartik Magadum

The for loop and comment is correct as dynamic content block uses that syntax for < and for comment as well