- 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-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 04:11 AM
Hi Aniket,
I'm getting below like this. Please help me regarding this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 04:28 AM
Hello @Sirri ,
Understood, that is happening because those are the reference type variables so that's why the sys_id's are getting added that string variable, please try with the below code one and let me know how it works for you.
function onSubmit() {
// Get display values from the form fields
var requestedForDisplay = g_form.getDisplayValue('requested_for');
var fullAccessToPersonDisplay = g_form.getDisplayValue('full_access_to_person');
var leaverPersonDisplay = g_form.getDisplayValue('leaver_person');
var confirmationField = g_form.getValue('confirmation_field');
// Check if both fullAccessToPerson and leaverPerson are empty
if (!fullAccessToPersonDisplay && !leaverPersonDisplay) {
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 (fullAccessToPersonDisplay && leaverPersonDisplay) {
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 (fullAccessToPersonDisplay) {
g_form.setValue('confirmation_field', requestedForDisplay + ' - ' + fullAccessToPersonDisplay);
} else if (leaverPersonDisplay) {
g_form.setValue('confirmation_field', requestedForDisplay + ' - ' + leaverPersonDisplay);
}
// Allow the form submission
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 05:16 AM
Hi aniket,
Thank you
If I want to see the two users names in confirmation before the order. By using currently script I'm able to see after the order. Please let us know how we can achieve this.
Thank you