for loop is not working. There seems a problem in fetching arguments.

$w.onReady( function () {

function gstrStatus(a,b) {

if ($w( ‘#dynamicDataset’ ).getCurrentItem().a === “Filed” ) {
return $w(b).style.backgroundColor = “#68B04D

    }  **else if**  ($w( '#dynamicDataset' ).getCurrentItem().a ===  "Not filed" ) { 

return $w(b).style.backgroundColor = “#DB8688

    }  **else if**  ($w( '#dynamicDataset' ).getCurrentItem().a ===  "Submitted" ) { 

return $w(b).style.backgroundColor = “#f4f499

    }  **else if**  ($w( '#dynamicDataset' ).getCurrentItem().a ===  "NULL" ) { 

return $w(b).hide()
} else {
return $w(b).style.backgroundColor = “#DBDBDB

    } 

} 

let a=[ ‘gstr3BApr19’ , ‘gstr3BMay19’ , ‘gstr3BJun19’ ]
let b=[ ‘#boxApr3B’ , ‘#boxMay3B’ , ‘#boxJun3B’ ]
gstrStatus(a, b)
for ( var i = 0 ; i < a.length; i++) {gstrStatus(a, b)

} 

console.log(gstrStatus()); 

});

Error: The value passed to the element selector function (usually $w), must be of type string ---- Line 19


This code need to be looped:

$w.onReady(function () {

function gstrStatus() { 

	if ($w('#dynamicDataset').getCurrentItem().gstr3BApr19 === "Filed") { 
		return $w('#boxApr3B').style.backgroundColor = "#68B04D" 

	} else if ($w('#dynamicDataset').getCurrentItem().gstr3BApr19 === "Not filed") { 
		return $w('#boxApr3B').style.backgroundColor = "#DB8688" 

	} else if ($w('#dynamicDataset').getCurrentItem().gstr3BApr19 === "Submitted") { 
		return $w('#boxApr3B').style.backgroundColor = "#f4f499" 

	} else if ($w('#dynamicDataset').getCurrentItem().gstr3BApr19 === "NULL") { 
		return $w('#boxApr3B').hide() 
	} else { 
		return $w('#boxApr3B').style.backgroundColor = "#DBDBDB" 

	} 

} 

console.log(gstrStatus()); 

});
$w.onReady(function () {
function gstrStatus() {
if ($w(‘#dynamicDataset’).getCurrentItem().gstr3BMay19 === “Filed”) {
return $w(‘#boxMay3B’).style.backgroundColor = “#68B04D

	} else if ($w('#dynamicDataset').getCurrentItem().gstr3BMay19 === "Not filed") { 
		return $w('#boxMay3B').style.backgroundColor = "#DB8688" 

	} else if ($w('#dynamicDataset').getCurrentItem().gstr3BMay19 === "Submitted") { 
		return $w('#boxMay3B').style.backgroundColor = "#f4f499" 

	} else if ($w('#dynamicDataset').getCurrentItem().gstr3BMay19 === "NULL") { 
		return $w('#boxMay3B').hide() 
	} else { 
		return $w('#boxMay3B').style.backgroundColor = "#DBDBDB" 

	} 

} 

console.log(gstrStatus()); 

});

$w.onReady(function () {
function gstrStatus() {
if ($w(‘#dynamicDataset’).getCurrentItem().gstr3BJun19 === “Filed”) {
return $w(‘#boxJun3B’).style.backgroundColor = “#68B04D

	} else if ($w('#dynamicDataset').getCurrentItem().gstr3BJun19 === "Not filed") { 
		return $w('#boxJun3B').style.backgroundColor = "#DB8688" 

	} else if ($w('#dynamicDataset').getCurrentItem().gstr3BJun19 === "Submitted") { 
		return $w('#boxJun3B').style.backgroundColor = "#f4f499" 

	} else if ($w('#dynamicDataset').getCurrentItem().gstr3BJun19 === "NULL") { 
		return $w('#boxJun3B').hide() 
	} else { 
		return $w('#boxJun3B').style.backgroundColor = "#DBDBDB" 

	} 

} 

console.log(gstrStatus()); 

});

Hello anybody can help me?

Hello @yisrael-wix please can you help me out why loop is not working. I am beginner.

Hi
I tried with a
container box - ‘boxApr3B’
containing a text field - ‘txtApr3B’.
That Text field display value of ‘gstr3BApr19’ field of a data set ‘#dynamicDataset’.
Input in ‘gstr3BApr19’ have four option i) 'Filed, ii) ‘Not filed’ iii) ‘Submitted’ iv) NULL means not applicable
container box to be filled with i) Green ii) Red iii) yellow and iv) white for there respective values.

$w.onReady(function () {

function gstrStatus() {

if ($w(‘#dynamicDataset’).getCurrentItem().gstr3BApr19 === “Filed”) {
return $w(‘#boxApr3B’).style.backgroundColor = “#68B04D

} else if ($w(‘#dynamicDataset’).getCurrentItem().gstr3BApr19 === “Not filed”) {
return $w(‘#boxApr3B’).style.backgroundColor = “#DB8688

} else if ($w(‘#dynamicDataset’).getCurrentItem().gstr3BApr19 === “Submitted”) {
return $w(‘#boxApr3B’).style.backgroundColor = “#f4f499

} else if ($w(‘#dynamicDataset’).getCurrentItem().gstr3BApr19 === “NULL”) {
return $w(‘#boxApr3B’).hide()
} else {
return $w(‘#boxApr3B’).style.backgroundColor = “#DBDBDB
}
}
console.log(gstrStatus());

// code is working fine.

Then I have 12 months meaning 12 container box, 12 text fields, 12 dataset fields with a difference of month name i.e Apr for April, May for May, Jun for June and so on. Now I want to create a ‘for loop’ but the same is not working. What I find that you can’t replace ‘gstr3BApr19’ for ‘gstr3BMay19’ (i.e dataset fields) and ‘boxApr3B’ for ‘boxMay3B’.

Here is ‘for loop’ I created for 3 months but its not working with undefined results

$w.onReady( function () {

const currentItem = $w( ‘#dynamicDataset’ ).getCurrentItem()
let month = [ “gstr3BApr19” , “gstr3BMay19” , “gstr3BJun19” ];
let boxId = [$w( ‘#boxApr3B’ ), $w( ‘#boxMay3B’ ), $w( ‘#boxJun3B’ )]

function gstrStatus() {

if (currentItem.month[i] === “Filed” ) {
return boxId[i].style.backgroundColor = “#68B04D
} else if (currentItem.month[i] === “Not filed” ) {
return boxId[i].style.backgroundColor = “#DB8688

    }  **else if**  (currentItem.month[i] ===  "Submitted" ) { 

return boxId[i].style.backgroundColor = “#f4f499

    }  **else if**  (currentItem.month[i] ===  "NULL" ) { 

return boxId[i].style.backgroundColor = “white”
}

} 

for ( var i = 0 ; i < month.length; i++) {
console.log(gstrStatus())

} 

});

console.log() returns -
TypeError: Cannot read property ‘0’ of undefined

As I know it is not accepting array value. Probably taking as string not memory address.
But how can we create loop so that unnecessary lengthy code could be avoided.

Regard

Satyendra Kandari