I have a parent records with several children. I want to change some of them to another parent. It seems easy, change the FK of the child and it’s done. I can change the FK by hand but servoy refuses to do it through a method.
var firstParent = '1234'
var second parent = '5678'
for(t=1; t <= forms.z_all_action_attachment.controller.getMaxRecordIndex(); t++)
{
// finds all attachment for the groups mailing
forms.z_all_action_attachment.controller.find()
forms.z_all_action_attachment.act_att_rel = firstParent
forms.z_all_action_attachment.controller.search()
forms.z_all_action_attachment.act_att_rel = secondParent.
databaseManager.saveData()
}
It finds the firstParent’s children but it doesn’t change anything. If release the relation it works.
I don’t think youre code is wrong, maybe the secondKey has a wrong value?
You could try this code:
var firstParent = '1234'
var secondParent = '5678'
// finds all attachment for the groups mailing
forms.z_all_action_attachment.controller.find()
forms.z_all_action_attachment.act_att_rel = firstParent
var _found = forms.z_all_action_attachment.controller.search()
var _record
for(t=1; t <= _found; t++)
{
_record = forms.z_all_action_attachment.foundset.getRecord(t)
_record.act_att_rel = secondParent
}
databaseManager.saveData()
I don’t think youre code is wrong, maybe the secondKey has a wrong value?
You could try this code:
var firstParent = '1234'
var secondParent = '5678'
// finds all attachment for the groups mailing
forms.z_all_action_attachment.controller.find()
forms.z_all_action_attachment.act_att_rel = firstParent
var _found = forms.z_all_action_attachment.controller.search()
var _record
for(t=1; t <= _found; t++)
{
_record = forms.z_all_action_attachment.foundset.getRecord(t)
_record.act_att_rel = secondParent
}
databaseManager.saveData()
irenem:
I have a parent records with several children. I want to change some of them to another parent. It seems easy, change the FK of the child and it’s done. I can change the FK by hand but servoy refuses to do it through a method.
var firstParent = '1234'
var second parent = ‘5678’
for(t=1; t <= forms.z_all_action_attachment.controller.getMaxRecordIndex(); t++)
{
// finds all attachment for the groups mailing
forms.z_all_action_attachment.controller.find()
forms.z_all_action_attachment.act_att_rel = firstParent
forms.z_all_action_attachment.controller.search()
var firstParent = '1234'
var second parent = '5678'
for(t=1; t <= forms.z_all_action_attachment.controller.getMaxRecordIndex(); t++)
{
// finds all attachment for the groups mailing
forms.z_all_action_attachment.controller.find()
forms.z_all_action_attachment.act_att_rel = firstParent
forms.z_all_action_attachment.controller.search()
forms.z_all_action_attachment.act_att_rel = secondParent.
databaseManager.saveData()
}
Let me get it straight:
you park in two vars the old and the new fk
then you loop through a fset searching all the related items
1st question: If you search the children, the find+search procedure should be enough, right?
So why do yuo need a loop? To set the new fk to all the children? If so, only the last two instructions
Should be inside the loop… Or do I miss something?
2nd question: what happens after the search? Do you actually have a record selected?
Try to remove the loop and see if the new fk is assigned to the selected record.
1st question: If you search the children, the find+search procedure should be enough, right?
So why do yuo need a loop? To set the new fk to all the children? If so, only the last two instructions
You are absolutely right. I tried that at first, since it didn’t replace anything I thought that it maybe would if it has to do it one by one. But unfortunately…
2nd question: what happens after the search? Do you actually have a record selected?
Try to remove the loop and see if the new fk is assigned to the selected record.
Yes, the search is ok and it selects the fist record, then nothing happens.
Since the very same code works well with other tables, I think I’ ll replace my table with another “fresh made” one. Lets see what happens!