User can't GlideRecord the Incident table

rrincon
Kilo Explorer

Hi all,

 

I created a custom role to handle a custom table, similar to out-of-the-box Incident table.

So, a normal user can create an incident, and if it is assigned to the group where the user is member, it creates a new record on the custom table. So that user (or any of the group) can solve this incident on the custom table, not the OOTB Incident table.

Once the record is Resolved or Closed, it needs to update the parent one on the OOTB Incident table to assign to another group. I did this with a business rule.

Well, it turns out that this is not happening.

Even the user has read/write ACL permissions on the OOTB Incident table (incident & incident.* ACL's), it doesn't work.

 

Can someone guide me through here, please?

Thanks in advance!

1 ACCEPTED SOLUTION

It would probably be best to deactivate the current Business Rule, and create a copy of it, calling it "Custom - incident query" and the script would look like:



(function(){


        if (!gs.hasRole("itil") && !gs.hasRole("your_role_name_goes_here") && gs.isInteractive()) {


                  var u = gs.getUserID();


                  var qc = current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u);


                  gs.print("query restricted to user: " + u);


        }


})();



Change "your_role_name_goes_here" with your new role.



This would essentially give your new role read access to all your Incidents, assuming ACLs do as well.   Now I suggest this without knowing any of your processes or business requirements.  


View solution in original post

20 REPLIES 20

Jim Coyne
Kilo Patron

Can you share the Business Rule so we can help decipher the issue?


Hi Jim,



Sure, here it is:



var incNum = current.u_incident_number;



var grINC = new GlideRecord('incident');


grINC.addQuery('sys_id', incNum);


grINC.query();



if (grINC.hasNext())


{


      grINC.next();



      var group = new GlideRecord('sys_user_group');


      group.addQuery('name', 'CSC');


      group.query();



      if (group.hasNext())


      {


              group.next();


              grINC.assignment_group = group.sys_id;



              grINC.work_notes = current.work_notes;



              grINC.comments = current.comments;



              grINC.update();


      }


}



I did some tests with another users, but those users have ITIL role, besides my custom role.


This users just has this role, and I configured the ACLs on Incident to make this work, but apparently it didn't.


I also include those lines, right after the first GlideRecord to check if the user can read and write on the table:



gs.log("table: " + grINC.getTableName());


gs.log("can read: " + grINC.canRead());


gs.log("can write: " + grINC.canWrite());


gs.log("isValid: " + grINC.isValid());



And every time I found "true" on the log. So he can read and write on the table.



Any suggestion?


Is your GlideRecord query on incident pulling in any records?   To me it looks like you're querying for sys_id, but passing in the incident number and not the actual sys_id of the record.   Can you put a gs.log() statement inside your if statement?


Hi,



Yeah, I did that. This is the current script:



var incNum = current.u_incident_number.sys_id;


gs.log("current.u_incident_number.sys_id: " + incNum);



var grINC = new GlideRecord('incident');


gs.log("table: " + grINC.getTableName());


gs.log("can read: " + grINC.canRead());


gs.log("can write: " + grINC.canWrite());


gs.log("isValid: " + grINC.isValid());



grINC.get(incNum);


if (grINC)


{


      gs.log("current.u_incident_number: " + incNum + "\nname: Customer Service Center");



      var group = new GlideRecord('sys_user_group');


      group.get('name', 'Customer Service Center');



      if(group)


      {


              grINC.assignment_group = group.sys_id;


              gs.log("group.sys_id: " + group.sys_id);



              grINC.work_notes = current.work_notes;


              gs.log("grINC.work_notes: " + grINC.work_notes);



              grINC.comments = current.comments;


              gs.log("grINC.comments: " + grINC.comments);



              grINC.update();


      }


}



Still doesn't work, but now it throws this:



java.sql.BatchUpdateException: Duplicate entry '6445f8fb69d7910035b97f6af403b5f1' for key 'PRIMARY'



Any suggestions?