Getting error message - GlideScriptRecordUtil is not allowed in scoped applications

BijoyDeb
Tera Contributor

Hi All,

I have a custom table under custom scope on which I am trying to track durations taken by tickets to transition through different states.

Before creating metric definition on this table, I created a business in my custom scope, selected my custom table and copied script from 'metrics events' business rule which is as follows-  

 

queueMetricUpdate();

function queueMetricUpdate() {    
    var gru =  new GlideScriptRecordUtil.get(current);
    var fieldsChanged = gru.getChangedFieldNames();
    var gr = getDefinitions(fieldsChanged);
    fields = '';
    while (gr.next())
        fields += gr.field + ',';
   
    if (fields.length > 0) {
        fields = '[' + fields.substring(0, fields.length - 1) + ']';
        gs.eventQueue('metric.update', current, fields, current.sys_mod_count, 'metric_update');
    }
}

function getDefinitions(fields) {
    var gr = new GlideAggregate('metric_definition');
    gr.addActiveQuery();
    var tables = GlideDBObjectManager.getTables(current.getTableName());
    gr.addQuery('table', tables);
    gr.addQuery('field', fields);
    gr.groupBy('field');
    gr.query();
    return gr;
}
 
After that as per my metric definition, metrics are getting created, but each time I am changing the state I am getting below error-
 
BijoyDeb_0-1735820390542.png

 

Has anyone faced this issue before? Can you please let me know how to resolve this issue?

 

Thanks!

2 ACCEPTED SOLUTIONS

Runjay Patel
Giga Sage

Hi @BijoyDeb ,

 

In scop app all predefined API wont work and support due to security reason, in your case "GlideScriptRecordUtil" can not be use in scoped application. Check this script include and modify the access, or if it is in global application then user like "global.GlideScriptRecordUtil".

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@BijoyDeb 

basically you want to determine the changed fields in scoped app

use this as an alternative. I hope you are using after update BR to determine changed fields

queueMetricUpdate();

function queueMetricUpdate() {

    var fields = [];
    for (var key in current) {
        if (!key.toString().startsWith('sys') && (current[key] != previous[key])) {
            fields.push(key.toString());
        }
    }

    if (fields.length > 0) {
        fields = '[' + fields.substring(0, fields.length - 1) + ']';
        gs.eventQueue('metric.update', current, fields, current.sys_mod_count, 'metric_update');
    }
}

function getDefinitions(fields) {
    var gr = new GlideAggregate('metric_definition');
    gr.addActiveQuery();
    var tables = GlideDBObjectManager.getTables(current.getTableName());
    gr.addQuery('table', tables);
    gr.addQuery('field', fields);
    gr.groupBy('field');
    gr.query();
    return gr;
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Runjay Patel
Giga Sage

Hi @BijoyDeb ,

 

In scop app all predefined API wont work and support due to security reason, in your case "GlideScriptRecordUtil" can not be use in scoped application. Check this script include and modify the access, or if it is in global application then user like "global.GlideScriptRecordUtil".

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Hi @BijoyDeb ,

Thank you for marking my solution as helpful! The community now supports multi-solution acceptance, allowing you to accept multiple answers.

Ankur Bawiskar
Tera Patron
Tera Patron

@BijoyDeb 

basically you want to determine the changed fields in scoped app

use this as an alternative. I hope you are using after update BR to determine changed fields

queueMetricUpdate();

function queueMetricUpdate() {

    var fields = [];
    for (var key in current) {
        if (!key.toString().startsWith('sys') && (current[key] != previous[key])) {
            fields.push(key.toString());
        }
    }

    if (fields.length > 0) {
        fields = '[' + fields.substring(0, fields.length - 1) + ']';
        gs.eventQueue('metric.update', current, fields, current.sys_mod_count, 'metric_update');
    }
}

function getDefinitions(fields) {
    var gr = new GlideAggregate('metric_definition');
    gr.addActiveQuery();
    var tables = GlideDBObjectManager.getTables(current.getTableName());
    gr.addQuery('table', tables);
    gr.addQuery('field', fields);
    gr.groupBy('field');
    gr.query();
    return gr;
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader