- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 08:02 AM
Hello team,
I have to set the requested for variable in variable set as read only and change it to the user that is logged in and doing the request.
I have created this script, but it's not working fine, I have 3 options, the first one the user can change the requested for, but the other 2 no, so the script bellow only works when I change from the first option to the second, but if i change from the third option to the second it allows the user to change the requested for again.
Am I doing something wrong?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user=g_user.userID;
if(newValue == 'Remove access from a Group')
{
g_form.setMandatory("requested_for",true);
g_form.setValue("requested_for",user);
g_form.setReadOnly("variables.requested_for", true);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 08:53 AM
Hi @rafaelalves4337 ,
Please try the below, I have tested in PDI and it is working
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user = g_user.userID;
//Don't allow changes(opt 2)
if (newValue == 'Remove access from a Group') {
g_form.setMandatory("requested_for", true);
g_form.setValue("requested_for", user);
g_form.setReadOnly("requested_for", true);
}
//Allow changes(Option 1)
else if (newValue == '<update with opt 1>') {
g_form.setMandatory("requested_for", false);
g_form.setValue("requested_for", user);
g_form.setReadOnly("requested_for", false);
}
//Don't allow changes(opt 3)
else if (newValue == '<replace with opt3>') {
g_form.setMandatory("requested_for", false);
g_form.setValue("requested_for", user);
g_form.setReadOnly("requested_for", false);
}
}
Please mark this response correct if I've answered your question. Thanks!
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 08:43 AM
If this is your entire script you are missing else if conditions for the other 2 options, or just an 'else' if they are both the same. You shouldn't/don't need to specify 'variables.' in the setReadOnly. Outside of this script, do you have any other scripts or Catalog UI Policies that affect the requested_for variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 08:53 AM
Hi @rafaelalves4337 ,
Please try the below, I have tested in PDI and it is working
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user = g_user.userID;
//Don't allow changes(opt 2)
if (newValue == 'Remove access from a Group') {
g_form.setMandatory("requested_for", true);
g_form.setValue("requested_for", user);
g_form.setReadOnly("requested_for", true);
}
//Allow changes(Option 1)
else if (newValue == '<update with opt 1>') {
g_form.setMandatory("requested_for", false);
g_form.setValue("requested_for", user);
g_form.setReadOnly("requested_for", false);
}
//Don't allow changes(opt 3)
else if (newValue == '<replace with opt3>') {
g_form.setMandatory("requested_for", false);
g_form.setValue("requested_for", user);
g_form.setReadOnly("requested_for", false);
}
}
Please mark this response correct if I've answered your question. Thanks!
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 09:02 AM
I think that you will have to create an else statement to reset the values.
if (newValue == 'Remove access from a Group') {
g_form.setMandatory("requested_for",true);
g_form.setValue("requested_for",user);
g_form.setReadOnly("variables.requested_for", true);
} else if (newValue== 'Other Value' || newValue == 'Other Value' {
g_form.setMandatory("requested_for",true);
g_form.setValue("requested_for",user);
g_form.setReadOnly("variables.requested_for", true);
}
or switch over to a UI Policy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 09:04 AM
Sorry, forgot to chage the values in the else to be false..