Autopopulate two values in based on three fields.

Sirri
Tera Guru

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

-

1 ACCEPTED SOLUTION

Aniket Chavan
Tera Sage
Tera Sage

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

View solution in original post

12 REPLIES 12

You can use the Onchange Client script for this you just need to tweak the code a little bit,
Just use the approach as the field which would be filled last as the trigger field and display the confirmation field in the Alert. 

Hi Aniket, 

 

I'm getting sys id please help me here

Aniket Chavan
Tera Sage
Tera Sage

Hello @Sirri 

Is there any update on my response? if my response was helpful in addressing your query or If it assisted you in resolving your issue, kindly consider marking it as helpful, accepting the solution, and closing the thread. Doing so will not only acknowledge the assistance provided but also benefit future readers who might encounter a similar problem.

Thank you! 😁
Aniket.