Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Cannot find function getUniqueValue in object

pverni
Tera Contributor

Hello everyone,

 

I'm trying to create a Business Rule to execute a script that is originally locate in script actions (Evaluate assessment result for control).

 

But when I try to execute my business rule I receive this log erro:

 

com.glide.script.RhinoEcmaError: Cannot find function getUniqueValue in object b654bae7c3c53e10995c98fdd40131da.
sys_script_include.ec64a479008e3510f877f6eefcbd2717.script : Line(39) column(0)
36: // Chamada ao Script Include
37: var utils = new sn_grc.GRCSmartAssessmentUtils();
38: var asmtM2MScopeItem = utils.getCompletedAsmtScopeItemForGroup(assessmentGroupId, "sn_compliance_control", "ea0a83a07dd23110f87737f2fbd73143");
==> 39:
40: gs.info('*** BR: Objeto retornado pelo Script Include: ' + JSON.stringify(asmtM2MScopeItem));
41:
42: if (asmtM2MScopeItem && asmtM2MScopeItem.scope_item && asmtM2MScopeItem.scope_item.record) {
Stack trace:
at sys_script_include.ec64a479008e3510f877f6eefcbd2717.script:39
at sys_script.18cab9d7c3bcb210995c98fdd4013165.script:38 (executeRule)
at sys_script.18cab9d7c3bcb210995c98fdd4013165.script:53
at sys_ui_action.55b4f5c7c3b83210995c98fdd4013165.script:2

 

And my busines rule is bellow:

(function executeRule(current, previous /*null when async*/) {

    // Buscar último assessment vinculado ao controle
    var scopeItemGR = new GlideRecord('sn_smart_asmt_scope_item');
    scopeItemGR.addQuery('record', current.getUniqueValue());
    scopeItemGR.orderByDesc('sys_updated_on');
    scopeItemGR.setLimit(1);
    scopeItemGR.query();

    if (!scopeItemGR.next()) {
        gs.info('*** BR: Nenhum scope item encontrado para controle: ' + current.sys_id);
        return;
    }

    var m2mGR = new GlideRecord('sn_smart_asmt_m2m_instance_scope_item');
    m2mGR.addQuery('scope_item.record', current.getUniqueValue());
    m2mGR.orderByDesc('sys_updated_on');
    m2mGR.setLimit(1);
    m2mGR.query();

    if (!m2mGR.next()) {
        gs.info('*** BR: Nenhum relacionamento M2M encontrado para controle: ' + current.sys_id);
        return;
    }

    var grAssessment = new GlideRecord('sn_smart_asmt_instance');
    grAssessment.addQuery('sys_id', m2mGR.getValue('assessment_instance'));
    grAssessment.orderByDesc('sys_updated_on');
    grAssessment.setLimit(1);
    grAssessment.query();

    if (grAssessment.next()) {
        var assessmentGroupId = grAssessment.getValue('assessment_group');
        gs.info('*** BR: Assessment encontrado: ' + grAssessment.sys_id + ', grupo=' + assessmentGroupId);

        // Chamada ao Script Include
        var utils = new sn_grc.GRCSmartAssessmentUtils();
        var asmtM2MScopeItem = utils.getCompletedAsmtScopeItemForGroup(assessmentGroupId, "sn_compliance_control", "ea0a83a07dd23110f87737f2fbd73143");

        gs.info('*** BR: Objeto retornado pelo Script Include: ' + JSON.stringify(asmtM2MScopeItem));

        if (asmtM2MScopeItem && asmtM2MScopeItem.scope_item && asmtM2MScopeItem.scope_item.record) {
            var recordId = asmtM2MScopeItem.scope_item.record; // Corrigido
            utils.evaluateControl(recordId + '', grAssessment);
            gs.info('*** BR: Avaliação executada para controle: ' + current.sys_id);
        } else {
            gs.info('*** BR: Nenhum scope item completo encontrado para o grupo do assessment.');
        }
    } else {
        gs.info('*** BR: Nenhum assessment encontrado para controle: ' + current.sys_id);
    }

})(current, previous);

 

So, please, anyone can help me to solve this problem?

0 REPLIES 0