Invalid query detected, please check logs for details [Unknown field null in table incident]

Aakriti_Poudel
Tera Contributor
(function executeRule(current, previous /*null when async*/) {
    try {
        // Set up incident record
        var incidentGR = new GlideRecord('incident');
        incidentGR.initialize();
        incidentGR.setValue('short_description', 'Group Deleted: ' + current.name);
        incidentGR.setValue('assignment_group', '12a586cd0bb23200ecfd818393673a30'); // incident management group
        incidentGR.setValue('caller_id', '6816f79cc0a8016401c5a33be04be441'); // system administrator
        incidentGR.insert();
 
        // Send email notification
var groupName = current.name;
var incidentNum = incidentGR.number; 
 
gs.eventQueue('delete.notification.registry', incidentGR, current.name, incidentNum);
    } catch (ex) {
        gs.error('Error in business rule: ' + ex);
    }
})(current, previous);


 

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Did you check the logs for details?  If I had to guess, I would say it's this line that it doesn't like:

var incidentNum = incidentGR.number; 

You haven't executed a GlideRecord to return the entire record object that was created, so you can't reference a field in that object.

-O-
Kilo Patron
Kilo Patron

I don't think the problem is because of this code, but some other BR (or code) that is triggered by inserting an incident record.

To test this you should add instruction

incidentGR.setWorkflow(false);

before

incidentGR.initialize();

b.t.w, while at it, you should use

incidentGR.newRecord()

instead of initialize.

-O-
Kilo Patron
Kilo Patron

Additional info: as far as I know, errors with description "Invalid query detected" are produced by select filters, not other DB operations.

That is why, the code shown could not produce such errors - it only inserts, it does not filter and select.

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Aakriti_Poudel ,

 

Plz try with below code

 

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

    try {

        // Set up incident record

        var incidentGR = new GlideRecord('incident');

        incidentGR.initialize();

        incidentGR.setValue('short_description', 'Group Deleted: ' + current.name);

        incidentGR.setValue('assignment_group', '12a586cd0bb23200ecfd818393673a30'); // incident management group

        incidentGR.setValue('caller_id', '6816f79cc0a8016401c5a33be04be441'); // system administrator

        var sysID = incidentGR.insert();// fetch sysid of created incident

 

// Fetch incident number

var gr = new GlideRecord('incident');

if(gr.get(sysID)){

        // Send email notification

var groupName = current.name;

var incidentNum = gr.number; 

 

gs.eventQueue('delete.notification.registry', incidentGR, current.name, incidentNum);

}

    } catch (ex) {

        gs.error('Error in business rule: ' + ex);

    }

})(current, previous);

 

Thanks,

Danish