.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

This runs on the Requested Item [sc_req_item], correct?

Have you checked that "parent" is the correct field? Not that this should be "request" instead? I would expect:

reqRecord.addQuery('sys_id', current.request);

 

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

@Mark Roethof .

 

I tried to make some change as indicated in the below code and it is still not passing through the addition code to an existing REQ.  I was building a new RITM record using an existing catalog item and then adding it to an existing REQ.  This is what I am trying to do in the below code.  I am not sure if my response will be correct; I say yes that this runs off existing RITM.

 

// 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 27 <SP_SPNT_SN_INT_ManualConfigRITM> (ritm insert)");

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

I updated this part of the code after you asked to check the parent.

 

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

@Mark Roethof Good morning.  I managed to make the code run successfully and the below does not seem to create the new ritm and associate it to an existing REQ.  Is there some suggestion you can provide?

 

(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 11 <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();

if (accessTableGr.next()) {
gs.info("Business rule Line 19 <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 27 <SP_SPNT_SN_INT_ManualConfigRITM> (ritm insert)");

// Add the RITM to the current active REQ
var reqRecord = new GlideRecord('sc_request');
reqRecord.addQuery('number', current.request.number);
reqRecord.query();
if (reqRecord.next())
{
    gs.info("Line 35 <SP_SPNT_SN_INT_ManualConfigRITM>-Parent REQ returned " + reqRecord.getRowCount() + " records");
    reqRecord.insert(ritmGr.sys_id);
    gs.info("Line 37 <SP_SPNT_SN_INT_ManualConfigRITM>-Parent REQ Insert");
    reqRecord.update();
    gs.info("Line 38 <SP_SPNT_SN_INT_ManualConfigRITM>-Parent REQ Update");
}

gs.info("Business rule Line 40 <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);

adaptivert
Giga Guru

I did another change in the code as indicate below and I got the succeeding error. 

var reqRecord = new GlideRecord('sc_request');
reqRecord.addQuery('number', current.request.number);
reqRecord.query();
if (reqRecord.next())
{
    gs.info("Line 35 <SP_SPNT_SN_INT_ManualConfigRITM>-Parent REQ returned " + reqRecord.getRowCount() + " records");
    reqRecord.insert(ritmGr.sys_id);
    reqRecord.update();
}
------------------

Error in business rule <SP_SPNT_SN_INT_ManualConfigRITM> : com.glide.script.fencing.access.ScopeAccessNotGrantedException: create access to sc_request not granted

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