On selection of variable value system should allow other variable to allow only specific formats

Jay N
Tera Contributor

Hi Experts,

 

Depending on selection of variable value, system should allow only specific set of format to other variable else it should alert.

 

Let me know if this can be achievable.

 

Requirement: On selection of Operating system value from the drop down, File system variable should allow specific format (example: 

Windows - Drive name; examples: D:, or M:\dir1\dir2 are allowed. 
Linux/UNIX - Include File System Name only; example: /usr/local are allowed.)

JayN_0-1723121356954.png

JayN_1-1723121468764.png

 

I have used regex expression on change of only one variable "file System". Here is the code.

 

JayN_2-1723121806978.png

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below

    var pattern = /^([a-zA-Z]|[a-zA-Z]:|[a-zA-Z]:\\|[a-zA-Z]:\\[a-zA-Z0-9]*\\|[a-zA-Z]:\\[a-zA-Z0-9]*|[a-zA-Z]:\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*|[a-zA-Z]:\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*|[a-zA-Z]:\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*|[a-zA-Z]:\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*|[a-zA-Z]:\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*\\[a-zA-Z0-9]*|\/[a-zA-Z0-9]*|\/[A-Za-z0-9]*\/[A-Za-z0-9]*|\/[A-Za-z0-9]*\/[A-Za-z0-9]*\/[A-Za-z0-9]*|\/[A-Za-z0-9]*\/[A-Za-z0-9]*\/[A-Za-z0-9]*\/[A-Za-z0-9]*|\/[A-Za-z0-9]*\/[A-Za-z0-9]*\/[A-Za-z0-9]*\/[A-Za-z0-9]*\/[A-Za-z0-9]*|\/[A-Za-z0-9]*\/[A-Za-z0-9]*\/[A-Za-z0-9]*\/[A-Za-z0-9]*\/[A-Za-z0-9]*\/[A-Za-z0-9]*)$/; // regex pattern
    //var pattern = /^\/[a-z0-9]*$/
    if (!pattern.test(newValue)) {
        alert("Windows - Drive name; examples: D:, or M:\\dir1\\dir2 are allowed \n Linux/UNIX - Include File System Name only; example: /usr/local are allowed");
        g_form.setValue('src_ilc_atofs', '');
        g_form.showFieldMsg('src_ilc_atofs', "Windows - Drive name; examples: D:, or M:\\dir1\\dir2 are allowed.");
        g_form.showFieldMsg('src_ilc_atofs', "Linux/UNIX - Include File System Name only; example: /usr/local are allowed.");

    }
}
 
Experts need your suggestions.
 

Thanks, Jay

 

1 REPLY 1

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Jay N 

 

You can try the below Script

On change client script of variable (file system)

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var fileSystemVar = g_form.getValue('operating_system');
	alert(fileSystemVar) ;
    var fileSystemValue = g_form.getValue('file_system');
	var windowsPattern = /^[A-Z]:\\(?:[^<>:"/\\|?*\n\r]+\\)*[^<>:"/\\|?*\n\r]*$/;
    var linuxPattern = /^\/[A-Za-z0-9_\/]*$/;
    if (fileSystemVar == 'windows') {
        if (!windowsPattern.test(fileSystemValue) && fileSystemValue !== '') {
            alert('Please enter a valid Windows drive path');
            g_form.setValue('file_system', ' ');
        }
    } else if (newValue == 'linux') {
        if (!linuxPattern.test(fileSystemValue) && fileSystemValue !== '') {
            alert('Please enter a valid Linux/UNIX path, e.g., /usr/local.');
            g_form.setValue(''file_system', ' ');
        }
    }

    g_form.setValue('file_system_variable_name', '');
}

 

 

Thanks and Regards

Sai Venkatesh