- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 06:01 AM
i made this function to take user preference in script server:


it returns me an object, why?
The value is a string.

Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2022 05:22 AM
Hi Fabrizio,
According to the documentation, getPreference() returns a "String". Note the uppercase "S". This denotes that the returned type is an Object of type String. This is different from primitive type "string".
https://www.w3schools.com/js/js_typeof.asp
https://www.tutorialsteacher.com/articles/how-to-get-type-of-object-in-javascript
Try the following using "new String()". This will return an object of type "String" and not a primitive "string".
prefReport = new String('test');
gs.info(typeof(prefReport));
Result:
*** Script: object
If it's necessary to get type as a string, use "String()" without the "new" to create a primitive "string".
var prefReport = String(gs.getUser().getPreference('alm_asset.db.order'));
gs.info(typeof(prefReport));
Result
*** Script: string

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 06:41 AM
Also, if you have added user preference in this session, try login out and then login back to verify.
And if you are using client script just use:
getPreference("DESIRED_PREFERENCE_NAME");
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 06:34 AM
Hi Fabrizio,
If it is a property then you can use
data.mainReportPrefrence=gs.getProperty('custom_report_admin');
to get the value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2022 05:22 AM
Hi Fabrizio,
According to the documentation, getPreference() returns a "String". Note the uppercase "S". This denotes that the returned type is an Object of type String. This is different from primitive type "string".
https://www.w3schools.com/js/js_typeof.asp
https://www.tutorialsteacher.com/articles/how-to-get-type-of-object-in-javascript
Try the following using "new String()". This will return an object of type "String" and not a primitive "string".
prefReport = new String('test');
gs.info(typeof(prefReport));
Result:
*** Script: object
If it's necessary to get type as a string, use "String()" without the "new" to create a primitive "string".
var prefReport = String(gs.getUser().getPreference('alm_asset.db.order'));
gs.info(typeof(prefReport));
Result
*** Script: string

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2022 05:34 AM
Hi again,
To check the type of object, use instanceof instead of typeof.
e.g.
var prefReport = gs.getUser().getPreference('alm_asset.db.order');
gs.info(prefReport instanceof String);
Result
*** Script: true