OnSubmit client script to exclude count of some device type

Ankita9793
Tera Contributor

Hi All,

 

If Device Type is 'Standard Virtual Desktop' OR 'Virtual Desktop' OR 'Enhanced Virtual Desktop' then the script should not count/ exclude that item from the count. Please suggest, how can it be done.

Below is the OnSubmit Client Script:

 

function onSubmit() {
 
g_form.clearMessages();
 
if(!g_form.isFormValidated) {
g_form.addErrorMessage(getMessage('hsbc.hardware.restrict.country'));
return false;
}
 
//script to check that the multi row variable set has been completed correctly and all items have been completed
//only run if the multiple row variable set exists on the form
//var device = g_form.getValue(device_type);
//if (device != 'Standard Virtual Desktop' || device != 'Virtual Desktop' || device != 'Enhanced Virtual Desktop'){
//alert('device type' + device);
if (g_form.hasField('tu_multiple_laptop_additional')){
if ( g_form.getValue( 'tu_multiple_laptop_additional' ).length > 0 ) {
var itemsLeftCount = 0;
var machine = JSON.parse(g_form.getValue('tu_multiple_laptop_additional'));
 
for(var i=0; i < machine.length; i++) {
if (machine[i].actiondevice == ''){
itemsLeftCount ++;
}
}
if (itemsLeftCount > 0){
if(itemsLeftCount ==1){
alert('device count' + itemsLeftCount);
g_form.addErrorMessage('User Owned Devices: You have 1 item which requires completing before you can submit');
}
else{
g_form.addErrorMessage('User Owned Devices: You have '+itemsLeftCount+' items which require completing before you can submit');
alert('device count' + itemsLeftCount);
}
return false;
}
}
}
//}
 
 
}
1 REPLY 1

Aniket Chavan
Tera Sage
Tera Sage

Hello @Ankita9793 

You can give a shot the below script in which I have made some changes, as I didn't tested it you can let me know if that not worked for you.

function onSubmit() {

    g_form.clearMessages();

    if (!g_form.isFormValidated) {
        g_form.addErrorMessage(getMessage('hsbc.hardware.restrict.country'));
        return false;
    }

    // Check if the multiple row variable set exists on the form
    if (g_form.hasField('tu_multiple_laptop_additional')) {
        if (g_form.getValue('tu_multiple_laptop_additional').length > 0) {
            var itemsLeftCount = 0;
            var machine = JSON.parse(g_form.getValue('tu_multiple_laptop_additional'));

            for (var i = 0; i < machine.length; i++) {
                // Check if the device type is not one of the excluded types
                if (machine[i].actiondevice !== 'Standard Virtual Desktop' &&
                    machine[i].actiondevice !== 'Virtual Desktop' &&
                    machine[i].actiondevice !== 'Enhanced Virtual Desktop') {
                    if (machine[i].actiondevice === '') {
                        itemsLeftCount++;
                    }
                }
            }

            if (itemsLeftCount > 0) {
                if (itemsLeftCount === 1) {
                    alert('device count' + itemsLeftCount);
                    g_form.addErrorMessage('User Owned Devices: You have 1 item which requires completing before you can submit');
                } else {
                    g_form.addErrorMessage('User Owned Devices: You have ' + itemsLeftCount + ' items which require completing before you can submit');
                    alert('device count' + itemsLeftCount);
                }
                return false;
            }
        }
    }
}

 

Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

Regards,
Aniket