Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Random behaviour of deleteInstance
lazybee26
This is for 6.5 on solaris
I'm populating replicant container using a callout. By rule, I want to delete all instances of the replicant, before writing any new data from the callout.
My clean_replicant (below) works very randomly.
Once the DCT is open
1. I click on the callout, select my desired values and press ok.
2. clean_replicant goes into action first, cleaning all existing replicants
3. new values get written into the replicant
These steps work fine only the 1st time. From then on every time I repeat the steps, delete instance status returns "false" increasingly.
Bottom line - my function doesn't delete all instances consistently.
Here's the snippet
// rep parameter is the replicant container
var scriptFrame = opener.top.getScriptFrame();
var rep = scriptFrame.IWDatacapture.getItem(xpath to replicant container);
function clean_replicant(rep)
{
var rep_length=rep.getChildren().length;
//alert(rep_length);
for (i=1;i<=rep_length;i++){
var s =rep.deleteInstance(i);
//alert (s);
}
}
Any tips would be helpful.
Thanks
Find more posts tagged with
Comments
Adam Stoller
You don't show us where you call clean_replicant().
You don't show up what alerts you get when you have the alerts enabled.
I'd recommend showing in the alerts the value of 'i' as well as 's'
I'm somewhat curirous as to the use-case of this callout - why you'd want to delete all instances of a replicant before inserting a new set [?] of instances.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
jbonifaci
lazy,
Your logic for deleting the replicants is a bit off. Lets say you have 10 replicants, your for loop is going to do this:
1st time: 10 instances in container, you delete instance 1.
2nd time: 9 instances in container, you delete instance 2.
3rd time: 8 instances in container, you delete instance 3.
4th time: 7 instances in container, you delete instance 4.
5th time: 6 instances in container, you delete instance 5.
6th time: 5 instances in container, you try to delete instance 6, but it obviously doesn't exist any more.
7th time: 5 instances in container, you try to delete instance 7, but it obviously doesn't exist any more.
8th time: 5 instances in container, you try to delete instance 8, but it obviously doesn't exist any more.
9th time: 5 instances in container, you try to delete instance 9, but it obviously doesn't exist any more.
10th time: 5 instances in container, you try to delete instance 10, but it obviously doesn't exist any more.
Rework your logic to either remove them from the end first, or just remove the first one N times.
~Jeff
lazybee26
Dude - Thanks Jeff !!! Thanks for explaining it so well. It works now. I just delete stuff in reverse, as you recommended.
Fish -
I'm calling clean_replicant within set_datacapture_item_value, right before setting new values
Use Case
1. The callout is used to select a bunch of values from a multi select drop down
2. Each multi select value maps to 3 items within a hidden replicant container. The 3 values are extracted from the multiselect value.
3. so user chooses 2 values from the multi select callout, it'll create 2 hidden replicant instances.
4. If user modifying some existing information.....It'll be easier for me to just delete all instances and start with a clean slate, instead of figuring out, which ones are newly selected values and adding those.
But I'm open to change my logic if there's a cleaner/better approach.
Thanks a lot Fish and Jeff, for all the help.
Lazy