Problem with ScopedGlideRecord

filip11
Giga Contributor

Hello there,

I am currently building a custom application with its own scope in the Fuji version. The problem that I encountered and couldn't deal with for quite some time now, is that it seems I can't access many methods of ScopedGlideRecord (I have tried even GlideRecord, with the same result). The context is, I'm trying to calculate a time duration according to the user's schedule in a before business rule, to populate a field before submitting.

This is the script I'm running:

function onBefore(current, previous) {

      var currUserID = gs.getUserID();

      var gr = new GlideRecord("sys_user");

      var currUser = gr.get(currUserID);

      var currSchedule = currUser.getValue('schedule');

//other logic

}

currUser is true, so the record is found. However all information I can get from it is the sys_id, which matches. If I turn on debugging and put the last statement into a try-catch block I get the following exception: Exception:: TypeError: undefined is not a function.

I'm currently really lost, all that I can think of is some kind of ACL which keeps me from accessing the values in the sys_user table from another scope.

I will be very thankful for any kind of suggestion.

Thank you very much!

1 ACCEPTED SOLUTION

ohhgr
Kilo Sage
Kilo Sage

Hi Filip,



GlideRecord get() function returns boolean value and not the reference. Could you try below lines of code and check if schedule is returned to you correctly.



var currUserID = gs.getUserID();


var currUser = new GlideRecord("sys_user");  


currUser.get(currUserID);  


var currSchedule = currUser.getValue('schedule');  



Thanks,
Mandar


View solution in original post

3 REPLIES 3

ohhgr
Kilo Sage
Kilo Sage

Hi Filip,



GlideRecord get() function returns boolean value and not the reference. Could you try below lines of code and check if schedule is returned to you correctly.



var currUserID = gs.getUserID();


var currUser = new GlideRecord("sys_user");  


currUser.get(currUserID);  


var currSchedule = currUser.getValue('schedule');  



Thanks,
Mandar


filip11
Giga Contributor

Hello Mandar,



Indeed, this was exactly the cause of the problem. After all the problems I encountered when trying to code a scoped application (opposed to global ones) I literally forgot how to use a GlideRecord.



Thank you very much for your quick reply!


Glad that it helped..


-Mandar