.MethodNotAllowedException: Function getGlideRecord is not allowed in scope

adaptivert
Giga Guru

Hello.  I need some suggestion or guidance on how best to overcome the following error.  I am wondering what would be the solution to resolve this error.

 

Error in business rule <SP_SPNT_SN_INT_ManualConfigRITM> : JavaException: com.glide.script.fencing.MethodNotAllowedException: Function getGlideRecord is not allowed in scope x_sap_intidn

 

This is from a business rule with the below code.  The trigger to run are Item is Sailpoint Access Request - Service Catalog, state changes to closed complete and stage changes to completed before update.  

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

Cross Scope Privileges configured 

Source Scope Target Scope Target Name Operation Status
SailPoint IdN for Service Catalog SailPoint for Service Desk sc_req_item Write Allowed
SailPoint IdN for Service Catalog SailPoint for Service Desk sc_request Read Allowed
SailPoint IdN for Service Catalog SailPoint for Service Desk sc_request Create Allowed
SailPoint IdN for Service Catalog SailPoint for Service Desk sc_req_item Read Allowed
SailPoint IdN for Service Catalog SailPoint for Service Desk sc_req_item Create Allowed
SailPoint IdN for Service Catalog SailPoint for Service Desk sc_request Write Allowed
SailPoint IdN for Service Catalog SailPoint for Service Desk SP_SPNT_SN_INT_ManualConfigRITM Execute API Allowed
SailPoint IdN for Service Catalog Global SP_SPNT_SN_INT_ManualConfigRITM Execute API Allowed
SailPoint for Service Desk Global SP_SPNT_SN_INT_ManualConfigRITM Execute API Allowed
SailPoint for Service Desk SailPoint IdN for Service Catalog SP_SPNT_SN_INT_ManualConfigRITM Execute API Allowed
------------------------

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

(function executeRule(current, previous /*null when async*/) {
var catItemGr = new GlideRecord('sc_cat_item', 'Sailpoint IdN for Service Catalog');
catItemGr.get('name', 'Sailpoint Access Request');

try {
if (!current.variables.u_access_action || !current.variables.u_access_name) {
gs.info("Input validation failed <SP_SPNT_SN_INT_ManualConfigRITM>");
return;
}

gs.info("Business rule Line 12 <SP_SPNT_SN_INT_ManualConfigRITM> : " + current.variables.u_access_action.toString());

// Read the manual work table if access profile requires manual work
var accessTableGr = new GlideRecord('x_sap_intidn_manual_work_definition');
accessTableGr.addQuery('u_access_obj_name', current.variables.u_access_name.toString());
accessTableGr.query();

gs.info("<SP_SPNT_SN_INT_ManualConfigRITM>-accessTabGr.query() returned " + accessTableGr.getRowCount() + " records");

if (accessTableGr.next()) {
gs.info("Business rule Line 21 <SP_SPNT_SN_INT_ManualConfigRITM>: record matched");

// Create a new RITM record
var ritmGr = new GlideRecord('sc_cat_item');
ritmGr.name = catItemGr.name;
ritmGr.description = catItemGr.description;
ritmGr.insert();

gs.info("Line 29 <SP_SPNT_SN_INT_ManualConfigRITM> (ritm insert)");

// Add the RITM to the current active REQ
var reqRecord = current.parent.getGlideRecord();
reqRecord.addItem(ritmGr.sys_id);
reqRecord.update();

gs.info("Business rule Line 36 <SP_SPNT_SN_INT_ManualConfigRITM>");
gs.info("RITM created successfully. RITM sys_id <SP_SPNT_SN_INT_ManualConfigRITM: " + ritmGr.sys_id);
} else {
gs.info("No matching manual work definition found <SP_SPNT_SN_INT_ManualConfigRITM>");
}
} catch (err) {
gs.error("Error in business rule <SP_SPNT_SN_INT_ManualConfigRITM> : " + err);
}
})(current, previous);
1 ACCEPTED SOLUTION

adaptivert
Giga Guru

Just sharing the code I am able to successfully code to make it work.

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

(function executeRule(current, previous /*null when async*/) {
var catItemGr = new GlideRecord('sc_cat_item');
catItemGr.get('name', 'Sailpoint Access Request');

try {
    if (!current.variables.u_access_action || !current.variables.u_access_name)
    {
        gs.info("Input validation failed <SP_SPNT_SN_INT_ManualConfigRITM>");
        return;
    }

    gs.info("Business rule Line 12 <SP_SPNT_SN_INT_ManualConfigRITM> : " + current.variables.u_access_action.toString());

    // Read the manual work table if access profile requires manual work
    var accessTableGr = new GlideRecord('x_sap_intidn_manual_work_definition');
    accessTableGr.addQuery('u_access_obj_name', current.variables.u_access_name.toString());
    accessTableGr.query();
    current.stage

    if (accessTableGr.next())
    {
        gs.info("Business rule Line 22 <SP_SPNT_SN_INT_ManualConfigRITM>: record matched");

        // Create a new RITM record
        var ritmGr = new GlideRecord('sc_req_item');
        ritmGr.initialize();
        ritmGr.cat_item = catItemGr.sys_id;
        ritmGr.request = current.request.sys_id;
        ritmGr.assignment_group = accessTableGr.u_assign_group.sys_id;
        gs.info("Business rule Line 30 <SP_SPNT_SN_INT_ManualConfigRITM>: " + ritmGr.assignment_group.name.toString());
        ritmGr.short_description = "Manual Configuration: " + current.variables.u_access_action
                                    + "For " + current.variables.u_access_name;
        ritmGr.description = "Request Item related to  " + current.number  
                                + " For " + current.variables.u_access_name;
        ritmGr.opened_by = current.opened_by.toString();
        ritmGr.requested_for = current.requested_for.toString();
        ritmGr.state = -5;
        ritmGr.insert();

        gs.info("Business rule Line 40 <SP_SPNT_SN_INT_ManualConfigRITM>");
        gs.info("RITM created successfully. RITM sys_id <SP_SPNT_SN_INT_ManualConfigRITM: " + catItemGr.sys_id);
    }
    else
    {
        gs.info("No matching manual work definition found <SP_SPNT_SN_INT_ManualConfigRITM>");
    }
}
catch (err) {
gs.error("Error in business rule <SP_SPNT_SN_INT_ManualConfigRITM> : " + err);
}
})(current, previous);

View solution in original post

10 REPLIES 10

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Guess its about:

var reqRecord = current.parent.getGlideRecord();
 
Just update this. Retrieving the parent record through a separate query.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

@Mark Roethof .  Thank you for the suggestion. You are saying I replace that statement with something similar to the below (syntax is bad)?

 

var accessTableGr = new GlideRecord('sc_request');
accessTableGr.addQuery('u_access_obj_name', current.request.sysid);
accessTableGr.query();

@Mark Roethof .  would the below be a good replacement for var reqRecord = current.parent.getGlideRecord();?

 

var reqRecord = new GlideRecord('request');
reqRecord.addQuery('sys_id', current.parent.sys_id);
reqRecord.query();
if (reqRecord.next()) {
 reqRecord.addItem(tirmGr.sys_id);
 reqRecord.update();
}

i tested the below and it is not passing into the if statement because the query did not find the original REQ.  What should be a good code improvement to make this work?

 

// Add the RITM to the current active REQ
var reqRecord = new GlideRecord('sc_request');
reqRecord.addQuery('sys_id', current.parent.sys_id);
reqRecord.query();
if (reqRecord.next())
{
    gs.info("Line 35 <SP_SPNT_SN_INT_ManualConfigRITM>-Parent REQ returned " + accessTableGr.getRowCount() + " records");
    reqRecord.addItem(tirmGr.sys_id);
    reqRecord.update();
}