- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 09:55 AM
Hi All,
we have requirement in catalog item there are three fields
1)Requested for - Reference(sys_user)- [From Variable set]
2)Select the name of the person whose mailbox you need Full Access to - Reference(sys_user) - variable
3)Select the name of the Leaver whose mailbox you need Full Access to - Reference(sys_user) - Variable
4)Confirmation -Single Line Text(Readonly)
- When 2 & 3 fields are empty form should not submit please provide the code for this.
-When Both 2 & 3 are values filled form should not submit For this please provide code for this.
- In confirmation single line text we should want to populate 1&2 or 1&3 value As per the selection.
Please provide Clear code for this requirement.
Thank you
-
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 12:23 PM
Hello @Sirri
Yes you can achieve this all by using single onSubmit client script and validate everything in there, since I dont have your variable names so you can refer to the script below and replace the variables with your actual values, and let me know how it works for you or if you stuck somewhere.
onSubmit client script:
function onSubmit() {
// Get values from the form fields
var requestedFor = g_form.getValue('requested_for');
var fullAccessToPerson = g_form.getValue('full_access_to_person');
var leaverPerson = g_form.getValue('leaver_person');
var confirmationField = g_form.getValue('confirmation_field');
// Check if both fullAccessToPerson and leaverPerson are empty
if (!fullAccessToPerson && !leaverPerson) {
alert('Please fill either "Full Access to Person" or "Leaver Person" field.');
return false; // Do not submit the form
}
// Check if both fullAccessToPerson and leaverPerson have values
if (fullAccessToPerson && leaverPerson) {
alert('Please fill either "Full Access to Person" or "Leaver Person," not both.');
return false; // Do not submit the form
}
// Populate confirmationField based on the selection
if (fullAccessToPerson) {
g_form.setValue('confirmation_field', requestedFor + ' - ' + fullAccessToPerson);
} else if (leaverPerson) {
g_form.setValue('confirmation_field', requestedFor + ' - ' + leaverPerson);
}
// Allow the form submission
return true;
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 05:36 AM
Hello @Sirri ,
So in this scenario, you need to use the onChange client script but before that I want to confirm one thing that is the "Select the name of the person whose mailbox you need Full Access" & "Select the name of the Leaver whose mailbox you need Full Access to" both be will visible always or only one of them will be visible?
Just let me know your views on this one so that we can discuss about the further actions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 06:42 AM
Hi Aniket,
As per the selection "Select the name of the person whose mailbox you need Full Access" or "Select the name of the Leaver whose mailbox you need Full Access to" only one of them will visible with Requested for.
I hope you clear now. Please let me know how we can achieve this.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 07:15 AM
Hello @Sirri ,
Yes it's clear now, so you have to use two onChange client scripts for setting the value of confirmation variable , one will be used when "Select the name of the person whose mailbox you need Full Access" visible and one will be used when "Select the name of the Leaver whose mailbox you need Full Access to" visible,
also as you saying only one variable will be visible so hope you are already implemented logic behind it using UI policy or something, so you don't need to do any to fullfill these two criteria "When 2 & 3 fields are empty form should not submit and when Both 2 & 3 are values filled form should not submit" because currently the two onChange client scripts which I have provided you below don't have the logic to restrict user from submitting the item if those two conditions are not satisfying so please let me know your views on this one, also in my opinion you should use UI policy to make visible either one of those two variables so that you will no need to use 3rd onSubmit client script.
Script for fullAccessToPersonDisplay onChange:
function onChangeFullAccessToPerson(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
return;
var requestedForDisplay = g_form.getDisplayValue('requested_for');
var fullAccessToPersonDisplay = g_form.getDisplayValue('full_access_to_person');
if (fullAccessToPersonDisplay) {
g_form.setValue('confirmation_field', requestedForDisplay + ' - ' + fullAccessToPersonDisplay);
}
}
Script for leaverPersonDisplay onChange:
function onChangeLeaverPerson(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
return;
var requestedForDisplay = g_form.getDisplayValue('requested_for');
var leaverPersonDisplay = g_form.getDisplayValue('leaver_person');
if (leaverPersonDisplay) {
g_form.setValue('confirmation_field', requestedForDisplay + ' - ' + leaverPersonDisplay);
}
}
Please select the appropriate variables in in the both onChange client scripts and let me know if you have any queries further.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 04:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 12:31 PM
Hello @Sirri ,
It seems like you have added your code inside the onChange function means inside if condition so please adjust the code accordingly or else refer as below:
onChange client script for fullAccessToPerson:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var requestedForDisplay = g_form.getDisplayValue('requested_for');
var fullAccessToPersonDisplay = g_form.getDisplayValue('select_the_name_of_the_person_whose_mailbox_you_need_full_access_to');
if (fullAccessToPersonDisplay) {
// Move the following alert statement inside the if block if you want it to execute conditionally
alert('test1');
g_form.setValue('confirmation', requestedForDisplay + ' - ' + fullAccessToPersonDisplay);
}
}
onChange client script for leaverPersonDisplay:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var requestedForDisplay = g_form.getDisplayValue('requested_for');
var leaverPersonDisplay = g_form.getDisplayValue('select_the_name_of_the_leaver_whose_mailbox_you_need_full_access_to');
if (leaverPersonDisplay) {
g_form.setValue('confirmation', requestedForDisplay + ' - ' + leaverPersonDisplay);
}
// Move the following alert statement inside the if block if you want it to execute conditionally
alert('test2');
}
Hope this will resolves your current issue and let me know if anything else is remaining.
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket