User Profile Widget loads "default" view rather than "service portal" view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 02:54 PM
I am having an issue with certain users always seeing the default view when viewing the user profile widget in the service portal. Other users look to be seeing the service portal view.
I have tried loading these users with query parameters v= and view= and still no luck.
I tried cloning the widget and I did a Json.Stringify() and the object says its the service portal view.
var sysUserForm = $sp.getForm(data.table, data.sysUserID);
data.sysUserView = sysUserForm._view;
gs.addInfoMessage('user profile view is ' + JSON.stringify(sysUserForm));
output looks like this
Any way I can force this service portal view in the code? Only other option I see is in the client script is to add the list of fields I want to make sure are hidden in the field_excludes array. This isn't ideal as I would like to use the form designer to set certain fields as read only as well.
Thanks
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2021 03:53 PM
Ok, so after looking at the User Profile code I can understand the confusion....cause I definitely got confused. Also enjoyed the comment from whoever wrote this widget of " We need to handle this better."
The sysUserForm._view retrieves the fields laid out in the classic UI where the view name is "Service Portal". What it allows is for the 11 fields defined on the OOB view to be collected and returned without having to build an object manually in ServiceNow...adds a layer of flexibility that avoids needing to edit the widget.
The fields in the top section of the service portal widget are hardcoded to show company, title, department, location and bio.
The about section will show all the fields available on the "Service Portal" view, aslong as it isn't one of the fields defined in the fieldExcludes object defined in the client script:
var fieldExcludes = {
sys_user: ['name', 'introduction', 'title', 'department', 'location', 'photo',
'manager', 'company'],
live_profile: ['short_description', 'photo']
}
$sp.getForm() should be using the Service Portal view by default unless a view is specified so why you're getting the incorrect view at times I'm not sure. What you can do is modify the following line
var sysUserForm = $sp.getForm(data.table, data.sysUserID);
var sysUserForm = $sp.getForm(data.table, data.sysUserID, null, "sp");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 10:01 AM
I appreciate the help with this. I also enjoyed the comment for the fieldExcludes.
I tried using the var sysUserForm = $sp.getForm(data.table, data.sysUserID, null, "sp"); and still no luck. I have compared the objects for a user that is seeing the correct fields vs a user that is seeing additional fields that are not on the "sp" view. The only difference I see is the fields that are returned in sysUserForm._fields. I have not figured out what is causing the difference though.
If I view this users profile in the instance and select the service portal view it looks correct. When I impersonate and go to the actual portal is the only place it is wrong.
I am going to keep playing with this but it doesn't seem obvious what is happening.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2021 05:26 AM
Equally at a loss I'm afraid as that does appear to be strange behaviour.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 09:45 AM
You can force the view on the portal.
In the server script of your widget, you can set data.view = "<insert your portal view here>". Then pass this view as a parameter to getForm.
The getForm method takes in two more optional parameters, query and view. So you can just pass the view into the get form method and your data.f object should have everything you need to display properly.
data.f = $sp.getForm(data.table, data.sys_id, data.query, data.view);