- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 06:14 AM
Hi,
I have a scenario, on the sc_task form, a variable should be editable, if the logged in user belongs to certain group. I have written some part of the code. Kindly help.
Client Script
function onLoad() {
if (g_scratchpad.isMember == true)
{
g_form.
}
}
Business Rule
(function executeRule(current, previous /*null when async*/ ) {
if (gs.getUser().isMemberOf('TFS-ALABAMA') || gs.getUser().isMemberOf('TFS-BIRMINGHAM (RC)') || gs.getUser().isMemberOf('TFS-MID WEST'))
{
g_scratchpad.isMember = true;
}
})(current, previous);
This is the variable to be remained editable for the following groups.
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 07:03 AM - edited 12-20-2023 07:10 AM
The scratchpad variable is used in conjunction with onLoad Client Scripts when the Business Rule is triggered on display of the record, so change When to run:
Also, the value needs to be a string to get passed to the client, and it's a good idea to always set a value to prevent any errors on the client, so change your BR script:
(function executeRule(current, previous /*null when async*/ ) {
if (gs.getUser().isMemberOf('TFS-ALABAMA') || gs.getUser().isMemberOf('TFS-BIRMINGHAM (RC)') || gs.getUser().isMemberOf('TFS-MID WEST')) {
g_scratchpad.isMember = 'true';
} else {
g_scratchpad.isMember = 'false';
})(current, previous);
Then your Catalog Client Script would look like this:
function onLoad() {
if (g_scratchpad.isMember == 'false') {
g_form.setReadOnly('variable_name', true);
}
}
of course replacing variable_name with the name of your variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 06:55 AM
Hi @Community Alums ,
Why not implementing write ACL on field level? Then no scripting is needed ?
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 07:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 07:00 AM
Hi @Community Alums
Let's change your Business Rule with When is Display.
And from your Client Script, it will be looked like.
function onLoad() {
if (g_scratchpad.isMember == true){
g_form.setReadOnly('variables.<your_variable_name>', false);
return;
}
g_form.setReadOnly('variables.<your_variable_name>', true);
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 07:03 AM - edited 12-20-2023 07:10 AM
The scratchpad variable is used in conjunction with onLoad Client Scripts when the Business Rule is triggered on display of the record, so change When to run:
Also, the value needs to be a string to get passed to the client, and it's a good idea to always set a value to prevent any errors on the client, so change your BR script:
(function executeRule(current, previous /*null when async*/ ) {
if (gs.getUser().isMemberOf('TFS-ALABAMA') || gs.getUser().isMemberOf('TFS-BIRMINGHAM (RC)') || gs.getUser().isMemberOf('TFS-MID WEST')) {
g_scratchpad.isMember = 'true';
} else {
g_scratchpad.isMember = 'false';
})(current, previous);
Then your Catalog Client Script would look like this:
function onLoad() {
if (g_scratchpad.isMember == 'false') {
g_form.setReadOnly('variable_name', true);
}
}
of course replacing variable_name with the name of your variable.