Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello
I am using the below code for getting selection in my mashup
let fieldData = app.field('FinancialYear').getData() console.log(fieldData.rows)
console.log(fieldData.rows.length) // getting 0 everytime
So the issue is whenever I run the above code I am getting 0 lengths (cause I think that code gets run before the array is found )
so what I am trying to do is I want the last value of the array (2022-2023)
But after the dom load, I am getting 0 that the issue.
any help??
Hello mk,
getdata is an async operation, so you have to wait for it to end.
Use help site:
You can find a lot of stuff on this forum: Integration, Extension & APIs
Hello SerhanKaraer,
Thanks for reply
As per the example which you share I have added below code in Js file.
var fieldData = app.field('FinancialYear').getData(); fieldData.OnData.bind( function(){ fieldData.rows.forEach(function(row){ console.log(row.qElemNumber) }) }) fieldData.field('FinancialYear').select([0,1,2],true,true)
But now I am getting below error
Hi,
There seems a problem with the documentation.
It must be like this:
var fieldData = app.field('FinancialYear').getData();
fieldData.OnData.bind( function(){
fieldData.rows.forEach(function(row){
console.log(row.qElemNumber)
})
})
app.field('FinancialYear').select([0,1,2],true,true)
Hello SerhanKaraer,
Thanks for reply
var fieldData = app.field('FinancialYear').getData(); fieldData.OnData.bind( function(){ let value =[]; fieldData.rows.forEach(function(row){ value.push(row.qText) }) console.log([value.length -1 ]) app.field('FinancialYear').select([value.length -1 ],true,true) })
Now I am getting the last array value in the console and in selection as well
But now the console and selection value getting triggered each sec (so when you remove the selection it's get added automatically)
Hi,
When selection state changes on the server, the clients are updated with new selection state. This is the default behavior of QS. If you do not what to be updated, you have to unbind the listener as below:
var fieldData = app.field('FinancialYear').getData();
let value =[];
var listener = function() {
fieldData.rows.forEach(function(row){
value.push(row.qText)
})
console.log([value.length -1 ])
fieldData.OnData.unbind( listener );
}
fieldData.OnData.bind( listener )
app.field('FinancialYear').select([value.length -1 ],true,true)
If you want to be updated, just comment the line with unbind method.
Hello SerhanKaraer,
Try with your code, but somehow it's not working as expected
Not getting any selection or console after adding the code
Thanks in advance
Just corrected parentheses and braces @mk09123
Hi SerhanKaraer,
Can you please correct and share the same
cause I tried but it's not working