For the Active Directory Group Field, change to the validation to not be case sensitive.

Dave_p
Giga Guru

Hi,

I have a requirement where we have a field called 'Active Directory Group'. So based on the drop down of variable 'Account type', the show field message of the 'Active Directory Group' changes and based on the selection, it accepts only particular kind of message format. Even though the message says something like 'sbx_' in small letters, some are entering in CAPS and it is clearing off the field. They want to accept all CAPS as well as small. I worked for small, I don't know how to make it to accept capitals. Kindly help.

 

1.png

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    g_form.hideFieldMsg("active_directory_group", "true");
    var group = newValue;
    var accounttype = g_form.getValue("account_type");
    if (accounttype == "Sandbox") {
        if (!group.toString().startsWith("sbx_")) {

            g_form.clearValue("active_directory_group");
            g_form.showFieldMsg("active_directory_group", "The Active Directory group should begin with sbx_ if the account is sandbox specific.");
        }
    } else {

        if (!group.toString().startsWith("cloud_aws")) {

            g_form.clearValue("active_directory_group");
            g_form.showFieldMsg("active_directory_group", "The Active Directory group should begin with cloud_aws if the account is not sandbox specific.");
        }
    }
}

 

2.png

 

3.png

 

4.png

 

Regards

Suman P.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Dave_p 

try this

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    g_form.hideFieldMsg("active_directory_group", "true");
    var group = newValue.toString().toLowerCase(); // Convert input to lowercase
    var accounttype = g_form.getValue("account_type");
    if (accounttype == "Sandbox") {
        if (!group.startsWith("sbx_")) {
            g_form.clearValue("active_directory_group");
            g_form.showFieldMsg("active_directory_group", "The Active Directory group should begin with sbx_ if the account is sandbox specific.");
        }
    } else {
        if (!group.startsWith("cloud_aws")) {
            g_form.clearValue("active_directory_group");
            g_form.showFieldMsg("active_directory_group", "The Active Directory group should begin with cloud_aws if the account is not sandbox specific.");
        }
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

3 REPLIES 3

J Siva
Tera Sage

Hi @Dave_p 

We had a similar requirement as well.

To address it, we created two fields: one for capturing user input and another, a read-only field, which retrieves the user input, converts it to lowercase, and stores it accordingly.

Then we used the read-only field value for our automations etc..

Regards,

Siva

Ankur Bawiskar
Tera Patron
Tera Patron

@Dave_p 

try this

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    g_form.hideFieldMsg("active_directory_group", "true");
    var group = newValue.toString().toLowerCase(); // Convert input to lowercase
    var accounttype = g_form.getValue("account_type");
    if (accounttype == "Sandbox") {
        if (!group.startsWith("sbx_")) {
            g_form.clearValue("active_directory_group");
            g_form.showFieldMsg("active_directory_group", "The Active Directory group should begin with sbx_ if the account is sandbox specific.");
        }
    } else {
        if (!group.startsWith("cloud_aws")) {
            g_form.clearValue("active_directory_group");
            g_form.showFieldMsg("active_directory_group", "The Active Directory group should begin with cloud_aws if the account is not sandbox specific.");
        }
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Muhammad Salar
Giga Sage

Hello, try by converting input to lower case
var group = newValue.toString().toLowerCase();

Regards