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-06-2023 05:51 AM
Thank you for the feedback. I tried the suggestion above but receive the error below and the variable is not made required.
onChange script error: ReferenceError: Item is not defined function () { [native code] }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2023 10:31 AM
Hi @Peter Bodelier and @Albert
I checked this further and it looks like the issue is the role defined in the beginning is what is setting additional information =yes and then the variables are required for that user. However, I need to add 2 roles to the script. PM user should set the variable additional information to yes. The variable should only then be required for the user with pmsubmitter role. Is there a better way to do this or can I get help with the script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2023 11:31 PM
Hi @Gemma4,
I still believe this can be done with Catalog UI Policies, but here is an improved 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_variable_name', true);
g_form.setMandatory('test2_variable_name', true);
}
//repeat for the other scenarios
else if (newValue == 'No' && g_user.hasRoleExactly("pmsubmitter")) {
//g_form.setMandatory('test1', false);
//g_form.setMandatory('test2', false);
g_form.setMandatory('variables.test1_variable_name', false);
g_form.setMandatory('variables.test2_variable_name', false);
}
}
You weren't closing the first g_user.hasRoleExactly properly and no need to use 'variables.' in client scripts.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2023 08:30 AM
Thank you so much for all the feedback. I feel like we are so close to having this resolved. Unfortunately the script above didn't mark anything required. Let me give a little history in what I done; in case it helps determine the root cause of this not working. I've also attempted to use ui policies initially and failed with that. I'll share my attempt in case you see an issue.
I created an order guide that utilizes a catalog item. Users with pmsubmitter role will submit the request. For example user Zane. Variables test1, test2 are on the order guide and required for the user to complete. Variables test4 and test5 are on the catalog item and need to be required after the request is submitted and after the manager (user with pm role; for example Abel) selects yes at additional items. As a result I changed the script to include test4 and test5 for the variables. See below. Finally users with pmsubmitter; (zane again) role need to go back in the request item just submitted and complete required fields on ritm in portal (I plan to notify them with an email if additional information is selected yes)
Below is the script update and attached is my ui policy example. Please let me know if you have any suggestions or questions I can help clarify. I'm open to any potential ideas to revise process to get this working.
Thanks!!
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('test4_variable_name', true);
g_form.setMandatory('test5_variable_name', true);
}
//repeat for the other scenarios
else if (newValue == 'No' && g_user.hasRoleExactly("pmsubmitter")) {
//g_form.setMandatory('test1', false);
//g_form.setMandatory('test2', false);
g_form.setMandatory('variables.test4_variable_name', false);
g_form.setMandatory('variables.test5_variable_name', false);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2023 10:47 AM
I also tried the following onchange script with no luck