Failed trying to execute on Connection

Utkarsha
Tera Contributor

Hello Experts,

I was working on a script to retrieve all the static and dynamic type of filters from the dashboard to create their copied version in global scope..We got a ask from one of our clients that the entire dashboard needs to be converted into global scope including filters associated. The issue with the script is that every time post execution showing same error message. Could anyone suggest me what could be the reason here? Any important step that I am missing out here?

Thank you in advance!

var filterListStatic = [];
var filterListDynamic = [];
var m2mgr = new GlideRecord('pa_m2m_dashboard_tabs');
m2mgr.addEncodedQuery('dashboard.nameSTARTSWITHGlobal Security dashboard');
m2mgr.query();
while (m2mgr.next()) {
    var dashboardName = m2mgr.dashboard.name.toString();
    var dashboardScope = m2mgr.dashboard.sys_scope.toString();
    var dashboardSysId = m2mgr.dashboard.sys_id;
    var portalgr = new GlideRecord('sys_portal');
    portalgr.addEncodedQuery('page=' + m2mgr.tab.page.sys_id);
    portalgr.query();
    while (portalgr.next()) {
        var prefgr = new GlideRecord('sys_portal_preferences');
        prefgr.addEncodedQuery('portal_section=' + portalgr.sys_id);
        prefgr.addQuery('name', 'renderer');
        prefgr.addQuery('value', 'com.glide.cms.RenderBlock');
        prefgr.query();
        while (prefgr.next()) {
            var grPortalPrefrep = new GlideRecord('sys_portal_preferences');
            grPortalPrefrep.addQuery('portal_section', portalgr.sys_id);
            grPortalPrefrep.addQuery('name', 'sys_id');
            grPortalPrefrep.query();
            while (grPortalPrefrep.next()) {
                var grReportPrefrepp = new GlideRecord('content_block_programmatic');
                grReportPrefrepp.addQuery('sys_id', grPortalPrefrep.value);
                grReportPrefrepp.query();
                while (grReportPrefrepp.next()) {
                    filterListDynamic.push(grReportPrefrepp.sys_id.toString());
                    var filDyScope = grReportPrefrepp.sys_scope.toString();
                    // gs.info(filDyScope);
                    if (filDyScope !== 'global') {
                        if (!filterListDynamic[dashboardName]) {
                            filterListDynamic[dashboardName] = {
                                "scope": dashboardScope,
                                "Dynamic Filters": {}
                            };

                        }
                       /* if (filterListDynamic.includes(newdyfilter.sys_id)) {
                            continue;
                        }*/

                        var newdyfilter = new GlideRecord('content_block_programmatic');
                        newdyfilter.initialize();
                        newdyfilter.name = grReportPrefrepp.name;
                        newdyfilter.category = grReportPrefrepp.category;
                        newdyfilter.frame = grReportPrefrepp.frame;
                        newdyfilter.active = grReportPrefrepp.active;
                        newdyfilter.conditional = grReportPrefrepp.conditional;

                        newdyfilter.two_phase = grReportPrefrepp.two_phase;
                        newdyfilter.programmatic_content = grReportPrefrepp.programmatic_content;
						newdyfilter.sys_scope='global';
						newdyfilter.insert();


                    }
				}
                    var grReportPrefrept = new GlideRecord('content_block_static');
                    grReportPrefrept.addQuery('sys_id', grPortalPrefrep.value);
                    grReportPrefrept.query();
                    while (grReportPrefrept.next()) {

                        filterListStatic.push(grReportPrefrept.sys_id.toString());
                        var filStScope = grPortalPrefrep.sys_scope.toString();
                        //gs.info(filStScope);


                    }
                
            }
        }
    }
}

    gs.info(filterListDynamic);
    gs.info(filterListStatic);

 

0 REPLIES 0