Server JavaScript error Cannot convert null to an object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 02:19 PM - edited 03-03-2023 02:25 PM
I need to pass the value of gs.getUserID() as a parameter in my function "showArchiveButton" from Script Include, to Server Script. But when assigning the value of the userID variable, the console returns the error "Server JavaScript error Cannot convert null to an object."
My code:
var userID = gs.getUserID();
var include = new x_.UtilsKnowledge();
data.canArchive = include.showArchiveButton(userID);
showArchiveButton function in the Script Include:
showArchiveButton: function(userID) {
var author = current.getValue("u_author");
var tec_leader = current.u_lideres_tecnicos ? current.getValue("u_lideres_tecnicos").toString() : "";
var analyzer = current.u_analisadores ? current.getValue("u_analisadores").toString() : "";
var validators = current.u_validadores ? current.getValue("u_validadores").toString() : "";
var status = current.getValue("sinapsenow_status");
if (
(author == userID && status == 0) ||
(tec_leader == userID && status == 10) ||
(analyzer.indexOf(userID) != -1 && status == 20) ||
(validators.indexOf(userID) != -1 && status == 30) ||
(validators.indexOf(userID) != -1 && status == 50)
) {
return true;
}
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 04:11 PM
I don't think you actually need to pass that along. The Script Include is being called by the user so why not just put var userID = gs.getUserID(); directly in the Script Include instead?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 05:05 AM
The var userID = gs.getUserID() is already in the Include Script, I just forgot to put it in the question. But the error persists even with gs.getUserID() directly in the Include Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 06:30 AM
Does the Script Include return correctly when you hard-code a user's sys_id instead of using gs.getUserID()?
If it does, the ID could be in an incorrect format for use elsewhere in the script when using gs.getUserID(). In situations I've come across, that's just a matter of appending .toString() so it works properly.
If it doesn't, that makes me think there is another part of your code that is likely not working and you should try doing some logging (gs.info() for the different variables and conditions) to find out what works and what doesn't.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 05:55 PM
I agree @SVimes , BTW @kojimagui are you doing hihop into the instance or logging-in with credentials?