1

In CSM Contacts having views ( like Case, Customer Self Service etc ). How to identify user currently selected view in Contacts through Rest API ( for example, if user currently using the "Customer Self Service". I need to know the customer exact selected view ).

Please provide detailed information. Otherwise please suggest alternate method for this. It will helpful for us.Thanks!

find reference SS,

enter image description here

Raja C
  • 139
  • 1
  • 12

1 Answers1

1

The table you want to query is sys_user_preference.

The preference you are querying for is: <table_name>_list.view - I'm not sure what the internal name of the Contacts table is (try "contact"), but for the Incidents table it's "incident", so I'll show you with that.

Do a REST API to:

https://your-instance.service-now.com/api/now/table/sys_user_preference?sysparm_query=name=incident_list.view

You should get a response back with a JSON body. If you use the key result[0].value you should find the display name of the view. Note that this only works if the API is being executed by the user who wants to know their own preference.

Alternatively, you could create a scripted REST API which uses the following JS to find their preference:

var user = gs.getUser(); // get our user object
user = gs.getUserById('<their sys id>'); // get the user object we want the preference of
var pref = user.getPreference('incident_list.view');

return pref;

This would have to be executed by a user with permission to read the requested user's permission, however.

Sam L
  • 303
  • 1
  • 9
  • Thanks for the quick response. How can i get the meta fields from specific view using view name. – Raja C Aug 22 '19 at 14:10
  • That's a little more involved. You'll need to make a table request to `sys_ui_list_element` (all table columns), with a query that specifies the table and the view you're using. For some help constructing the query, check out the REST API explorer, or just use the filter builder on the table view. – Sam L Aug 22 '19 at 14:18
  • ok. Let me try sys_ui_list_element. Then another issue, unable to get the account selected view name using above suggested API (https://your-instance.service-now.com/api/now/table/sys_user_preference?sysparm_query=name=<>_list.view). Please advise. – Raja C Aug 22 '19 at 14:24
  • You need to replace the "your-instance" with your actual instance. Just browsing to that should cause basic auth to trigger (enter your S'Now credentials) and you'll get an XML document back where the "value" property is your currently chosen view. If you can't even get that then there may be permissions issues. – Sam L Aug 22 '19 at 14:31
  • I tried your suggestion. It works for customer_contact relationship. I can fetch the selected view. But it's not work for other relationships ( like account, consumers etc ) – Raja C Aug 22 '19 at 14:35
  • Is the result an empty body? If so, it could be that you have not changed your view - so the value would simply be "Default view" – Sam L Aug 22 '19 at 14:38
  • Great!. It's worked. Any chance to get default view name for contact/account relationships ? – Raja C Aug 22 '19 at 14:52
  • The default view is, from what I know, *always* called "Default view" – Sam L Aug 22 '19 at 14:59
  • Let me try and will reach you. – Raja C Aug 22 '19 at 15:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/198312/discussion-between-raja-c-and-azertify). – Raja C Aug 22 '19 at 15:14