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

 

1 REPLY 1

tejas1111
Giga 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.