How to use startWith() .

chandan31
Tera Contributor

Hi All,

 

var wsOptions4 = 'BR';
 var identifer = g_form.getValue('current_shift_identifier');
 if (wsOptions4.indexOf(identifer) >= 0) {
 g_form.setVisiable('test');
}
 
I want to use startWith() to search starting BR in the identifier 'var', can you guide me how to write the script.
 
 
Thanks,
Chandan
1 ACCEPTED SOLUTION

Try below.

 

var wsOptions4 = 'BR,SF,GI';
var splitis=wsOptions4.split(',');
 var identifer = g_form.getValue('current_shift_identifier');
for(var i=0;i<splitis.length;i++){
 if (identifer.substring(0,2)==splitis[i]) {
 g_form.setVisible('test',true);//true,false to show/hide
 }
}

 

View solution in original post

11 REPLIES 11

You want it to when when wsOptions4 is either BR, SF or GI?

 

yes ,one of the option

Try below.

 

var wsOptions4 = 'BR,SF,GI';
var splitis=wsOptions4.split(',');
 var identifer = g_form.getValue('current_shift_identifier');
for(var i=0;i<splitis.length;i++){
 if (identifer.substring(0,2)==splitis[i]) {
 g_form.setVisible('test',true);//true,false to show/hide
 }
}

 

var wsOptions4 = 'BR,SF,GI';
 var identifer = g_form.getValue('current_shift_identifier');
 if (wsOptions4.indexOf(identifer) >= 0) {
 g_form.setVisiable('test');
}
 
 
How to use startWith Function 

yaswanthi2
Giga Sage

Hi @chandan31 

you can try with startswith() like this

 

var wsOptions4 = 'BR';
var identifer = g_form.getValue('current_shift_identifier');
if (identifer.startsWith(wsOptions4)) {
g_form.setVisible('test',true);
}