Client Script not working on Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2017 10:03 AM
Hi Experts,
I understood, that normal client scripts will not work on service portal ... I also found some posts regarding this issue, but I don't get it. How to achieve ... you anyone please tell me in more detail what to do?
My on client scripts is something like this ...
function onLoad() {
if (g_form.getUniqueValue() !== g_user.userID)
{
g_form.removeOption('u_abc', 1);
g_form.removeOption('u_def', 1);
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2017 10:38 AM
Hello,
Yes. I don't see any issue with the script. Could you please check the field name ? Also, can you please check browser console log (in-case if you are getting any error).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2017 11:31 AM
Hi Vem
Not sure if you copied your code from the instance but if this is the case you have a missing {
function onLoad() {
if (!g_user.hasRole("xxxxxxx")){
alert("Disable should be removed");
g_form.removeOption('notification', 1);
}
Cheers
R0b0

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2017 12:36 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2017 12:45 AM
Hi Vem
I had a look around and i think Brian is right. g_user probably is not completely supported.
I mean g_user.getUserID works but not other methods. I think makes sense to open a ticket in HI.
On the other hand you can achieve the same result in a different way..create an async ajax call to obtain the user ID.
I know it's a different kind of effort just to obtain the user_id but it's the only way for the moment.
Cheers
R0b0

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2017 01:22 AM
Hi R0b0,
thanks! I would be fine with any workaround.
Just JS is already hard for me (as low-code person) ... ajax is absolutely not my area.
Could ou provide some code that could be used?
If fact i need an option to avoid showing certain sys_choice if it is not YOUR sys_user record you want to change ..
I also struggle hiding complete fields in the SP depending on other field values ... this client script is also not working ;-(
function onLoad() {
if (g_form.getValue('u_xxx') !== 'true') // check condition
g_form.setDisplay('u_yyy', false); // Hide field
}
Somehow lit looks like a lot of additional effort to get things running properly also in the SP .-(