Forum Discussion

R_'s avatar
R_
Creator I
9 years ago

Update ItemType programmatically

hi i want to update item type  which is iterated in for loop i write below code for that
for(int k=0;k<ir;k++)
{
  string itid= itarray.ToString();
  Item balItem1 = inn.newItem("bal_item","get");
  balItem1.setAttribute("id",itid);
  Item resbalItem1 = balItem1.apply();
  int iLockStatusItem=resbalItem1.getLockStatus();
  if (iLockStatusItem == 1 || iLockStatusItem==0)
  {
    if(iLockStatusItem==0)
    {
      resbalItem1.lockItem();
    }
    resbalItem1=resbalItem1.apply("update");
    resbalItem1.unlockItem();
  }
}
it gives error -An item with same key has already been added

3 Replies

  • Hi, hummm... not sure yet why it may fail. Can you a step by step debug and tell us where it exactly fails? on which line?
  • R_'s avatar
    R_
    Creator I
    i solve this problem by using config_is instead of id in setAtttribute() method
  • you know that if your itemtype is versionable, using config_id will potentially update every revision. Config_id is the common id to all the revisions of an item.