script is not running properly

chandan31
Tera Contributor
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var identifer = g_form.getValue('current_shift_identifier');
    var wsOptions2 = 'BR';
    var wsOptions1 = 'VR';
    var wsOptions3 = 'SR';

    var wsOptions4 = 'VUF';
    var wsOptions5 = 'VP';

    if ((identifer.startsWith(wsOptions2)) || (identifer.startsWith(wsOptions3)) || (identifer.startsWith(wsOptions1))) {
       

        g_form.removeOption('indicate_your_start_week', '6');
       

        g_form.setVisible('indicate_your_start_week', true);
       

    } else if ((identifer.startsWith(wsOptions4)) || (identifer.startsWith(wsOptions5))) {
       
       
        g_form.addOption('indicate_your_start_week', '6','6');
               
        g_form.setVisible('indicate_your_start_week', true);
       
    }
    else
        g_form.setVisible('indicate_your_start_week', false);

    //Type appropriate comment here, and begin script below

}
 
 
Hi All,,
 
This script is not running in onchange client script , in this script once the  field is disappear after that it is not visible while the current shift identiter field please modify the script .
3 ACCEPTED SOLUTIONS

Harsh_Deep
Giga Sage
Giga Sage

Hello @chandan31 

 

Please try this 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var identifer = g_form.getValue('current_shift_identifier');
    var wsOptions2 = 'BR';
    var wsOptions1 = 'VR';
    var wsOptions3 = 'SR';
    var wsOptions4 = 'VUF';
    var wsOptions5 = 'VP';

    if ((identifer.startsWith(wsOptions2)) || (identifer.startsWith(wsOptions3)) || (identifer.startsWith(wsOptions1))) {

        g_form.removeOption('indicate_your_start_week', '6');
        g_form.setVisible('indicate_your_start_week', true);
  
    } else if ((identifer.startsWith(wsOptions4)) || (identifer.startsWith(wsOptions5))) {
        g_form.addOption('indicate_your_start_week', '6','6');
        g_form.setVisible('indicate_your_start_week', true);  
    }
    else {
        g_form.setVisible('indicate_your_start_week', false);
}

}

 

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

View solution in original post

Hello @chandan31 ,

 

Use this - 

function onChange(control, oldValue, newValue, isLoading) {
    if (newValue == '') {
       getVal();
        return;
    }
getVal();
function getVal(){
    var identifer = g_form.getValue('current_shift_identifier');
    var wsOptions2 = 'BR';
    var wsOptions1 = 'VR';
    var wsOptions3 = 'SR';
    var wsOptions4 = 'VUF';
    var wsOptions5 = 'VP';

    if ((identifer.startsWith(wsOptions2)) || (identifer.startsWith(wsOptions3)) || (identifer.startsWith(wsOptions1))) {

        g_form.removeOption('indicate_your_start_week', '6');
        g_form.setVisible('indicate_your_start_week', true);
  
    } else if ((identifer.startsWith(wsOptions4)) || (identifer.startsWith(wsOptions5))) {
        g_form.addOption('indicate_your_start_week', '6','6');
        g_form.setVisible('indicate_your_start_week', true);  
    }
    else {
        g_form.setVisible('indicate_your_start_week', false);
}
}
}

 

This will execute onChange and onLoad as well.

 

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

View solution in original post

Amit Gujarathi
Giga Sage
Giga Sage

HI @chandan31 ,
I trust you are doing great.
Please refer the below updated code.

function onChange(control, oldValue, newValue, isLoading) {
    // Check if the form is loading or if the new value is empty, then exit the function
    if (isLoading || newValue == '') {
        return;
    }

    // Get the value of the 'current_shift_identifier' field
    var identifier = g_form.getValue('current_shift_identifier');

    // Define the identifiers that you want to check against
    var wsOptions = ['BR', 'VR', 'SR', 'VUF', 'VP'];

    // Check if the identifier starts with any of the defined options
    if (wsOptions.some(option => identifier.startsWith(option))) {
        // If identifier starts with 'BR', 'VR', or 'SR'
        if (['BR', 'VR', 'SR'].includes(identifier.substring(0,2))) {
            g_form.removeOption('indicate_your_start_week', '6');
        } 
        // If identifier starts with 'VUF' or 'VP'
        else if (['VUF', 'VP'].includes(identifier.substring(0,3))) {
            g_form.addOption('indicate_your_start_week', '6', '6');
        }

        // Make the 'indicate_your_start_week' field visible
        g_form.setVisible('indicate_your_start_week', true);
    } 
    // If identifier doesn’t match any option, hide the 'indicate_your_start_week' field
    else {
        g_form.setVisible('indicate_your_start_week', false);
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

10 REPLIES 10

Harsh_Deep
Giga Sage
Giga Sage

Hello @chandan31 

 

Please try this 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var identifer = g_form.getValue('current_shift_identifier');
    var wsOptions2 = 'BR';
    var wsOptions1 = 'VR';
    var wsOptions3 = 'SR';
    var wsOptions4 = 'VUF';
    var wsOptions5 = 'VP';

    if ((identifer.startsWith(wsOptions2)) || (identifer.startsWith(wsOptions3)) || (identifer.startsWith(wsOptions1))) {

        g_form.removeOption('indicate_your_start_week', '6');
        g_form.setVisible('indicate_your_start_week', true);
  
    } else if ((identifer.startsWith(wsOptions4)) || (identifer.startsWith(wsOptions5))) {
        g_form.addOption('indicate_your_start_week', '6','6');
        g_form.setVisible('indicate_your_start_week', true);  
    }
    else {
        g_form.setVisible('indicate_your_start_week', false);
}

}

 

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

This script is working but whole loading the form this script is not not working because current shift identifier field is populating during the onload .

 

Should i create same script in the on load form also

@chandan31 ,

 

Yes u can create on load as well so that it executes after the form load.

Mark Harsh answer as accepted if it helped u resolve your query.

 

Thanks,

Danish

 

Hello @chandan31 ,

 

Use this - 

function onChange(control, oldValue, newValue, isLoading) {
    if (newValue == '') {
       getVal();
        return;
    }
getVal();
function getVal(){
    var identifer = g_form.getValue('current_shift_identifier');
    var wsOptions2 = 'BR';
    var wsOptions1 = 'VR';
    var wsOptions3 = 'SR';
    var wsOptions4 = 'VUF';
    var wsOptions5 = 'VP';

    if ((identifer.startsWith(wsOptions2)) || (identifer.startsWith(wsOptions3)) || (identifer.startsWith(wsOptions1))) {

        g_form.removeOption('indicate_your_start_week', '6');
        g_form.setVisible('indicate_your_start_week', true);
  
    } else if ((identifer.startsWith(wsOptions4)) || (identifer.startsWith(wsOptions5))) {
        g_form.addOption('indicate_your_start_week', '6','6');
        g_form.setVisible('indicate_your_start_week', true);  
    }
    else {
        g_form.setVisible('indicate_your_start_week', false);
}
}
}

 

This will execute onChange and onLoad as well.

 

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