- 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:13 AM
A/C SN docs:
The getPreference() method returns a string containing the value of the preference requested, or null if no such preference is defined.
Can you explicitly change the value to string using JSON.stringify(prefReport); and check the alert or logs
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 06:27 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 06:38 AM
I tried this:
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 07:13 AM
var prefReport = gs.getUser().getPreference('custom_report.main');
yes, give me the value but if you try to write
gs.info(typeof(prefReport));
it gives me an object not a string, i need a string, i also tried JSON.stringify(prefReport) but it doesn't works