Client script to make variables mandatory- after submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2023 07:14 PM
Hi everyone,
I am trying to make variables mandatory after the request has been submitted, if the user has the pmsubmitter rule and if a custom field additional information is set to yes. I'm attempting to do this with a client script (below and attached) . Below is the script I am trying and attached are the results. When I impersonate a user after the request has been submitted, with the pmsubmitter role the platform is showing a black * instead of red indicating the field is required. In addition, the user that submits the request needs to be able to show these variables as required on the portal after summitted and their manager selects Yes at additional information. Unfortunately the variables are not getting set as required on the portal. Is this possible? In the past I've utilized sctasks and a flow to achieve. Below
Thank you in advance for any guidance you can provide!
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (g_user.hasRoleExactly("pmsubmitter"))
if (newValue === 'Yes') //yes
g_form.setMandatory('test1', true);
else
g_form.setMandatory('test1', false);
}
this but the requirement is to simply use the ritm for all the data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2023 07:34 PM
Also, I tried the following onchange client script using field additional information and didn't have any luck
//When: onChange
//onChange of field: u_additional information ---additional informaion
//Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//If the form is loading or the new value of the changing field is empty exit the script
if (isLoading || newValue == '') {
return;
}
if(newValue == 'Yes' && g_user.hasRoleExactly("pmsubmitter")) {
g_form.setMandatory('test1', true);
g_form.setMandatory('test2', true);
}
//repeat for the other scenarios
else if (newValue == 'No' && g_user.hasRoleExactly("pmsubmitter")) {
g_form.setMandatory('test1', false);
g_form.setMandatory('test2', false);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2023 07:49 PM
There could be a way to achieve this:
1. Create a client script (OnChange of Additional Information) or a UI Policy with Run scripts
2. Apply the conditions to only trigger the mandatory behavior to tickets that needs it (If necessary). Example: Apply only to that specific catalog item (Item == [sample_item] AND additional_info == yes)
3. Check for the Additional Information field's value and the user role -> Make any variable mandatory using example: g_form.setMandatory('variables.test1_variable_name', true);
Let me know if that helps. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2023 07:59 PM
Thank you so much for the feedback.
Below are the changes I made and after the changes made when I select Yes at additional information I receive the following error
Script error encountered when changing this field - please contact your System Administrator
Do you have any other suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2023 10:43 PM - edited ‎09-05-2023 10:44 PM
use g_form.setMandatory('variables.[insert your variable name here]', true);
If my Variable is Test1 with name test_1
code should be g_form.setMandatory('variables.test_1', true);