Greetings,
if one adds a template to a TemplateCanvas object via script by appending to the dataset one cannot access the newly created template in the same script.
Let say this code executes on a button action on a page containing a TemplateCanvas object “Canvas”, with a blank template dataset containing columns= [ name, template, x,y,width,height,z] eg default
Then appending a template is easy enough
canvas=event.source.parent.getComponent('Canvas')
cd=canvas.templates
cd=system.dataset.addRow(cd,["Template1","sometemplate", 0,0,100,100,0])
canvas.template=cd
templates=canvas.getAllTemplates()
The problem here is that templates returns an empty list instead of an instance of sometemplate
So thinking maybe template is created async on another thread and takes time to turn up
Append this to above code:
#really ugly code that should not really go into UI thread since it is blocking code
abortcount=0 #use to stop execution crashing UI
ncount=cd.rowCount-1 #have already added a row hence decrement
import time,sys
while len(canvas.getAllTemplates())==ncount and abortcount<100:
time.sleep(0.1)
abortcount+=1
it abortcount>=100:
sys.exit()
Now it times out.
After action completes template is visible and available.
So it seems the object only becomes available once script finishes execution.
Is this behaviour expected?
Is the only solution to fire of thread and do it async?