Service Portal Issue

Kartik Swaroop
Tera Contributor

Hey,

I  tried impersonating a user in servicenow and trying to access the new build portal.
But getting this error--

java.lang.NullPointerException: Cannot invoke "java.util.Map.containsKey(Object)" because "sourceFields" is null

 
it show the eforms, but for specific user, getting above error.

KartikSwaroop_0-1753057624421.png

 

2 REPLIES 2

TejasSN_LogicX
Tera Contributor

Hi @Kartik Swaroop ,

java.lang.NullPointerException: Cannot invoke "java.util.Map.containsKey(Object)" because "sourceFields" is null — typically indicates that some script or widget on the portal is trying to access a field or map that hasn't been initialized properly for the impersonated user.

 

Check the widget script (client/controller/server) and look for the code line using .containsKey(). Wrap that line with a null check:

 

if (sourceFields && sourceFields.containsKey('your_field')) {
  // safe to proceed
}

 

  • est the impersonated user’s profile:

    • Does the user have the same roles as the working user?

    • Is the user missing some mandatory field values (e.g., Department, Location, etc.)?

  • Use gs.info() or console.log() debugging in your widget/server script to log the state of sourceFields.

 

Sebastian Kring
Tera Contributor

Hi! 
I am not sure if the error is still relevant. However, I had the same error and in my case the reason was a missing translation. You can try to switch the language to English for the impersonated user and then give it another try in the Service Portal. Hope this helps!
Kind regards