update item changes programatically on itemtype save event

オフライン
hi all, i set property of item programmatically using following code  (C# code) Innovator inn=this.getInnovator(); string InvID = this.getProperty("id"); if(InvID !="" && InvID != null) { //get invoice item Item Invitem=inn.newItem("bal_invoice","get"); Invitem.setProperty("id",InvID); Item ResInv=Invitem.apply(); int InvCnt=ResInv.getItemCount(); if(InvCnt!=0) { //get inoive item property decimal transportAmt=0; decimal cessAmt=0; string transport=ResInv.getProperty("bal_transportation"); if(transport!=null) { transportAmt=Convert.ToDecimal(transport); } string cess=ResInv.getProperty("bal_cessamt"); if(cess!=null) { cessAmt=Convert.ToDecimal(cess); } //get invoice relation item Item relInv=inn.newItem("Bal_Invoice2Parts","get"); relInv.setProperty("source_id",ResInv.getID()); Item Resrelinv=relInv.apply(); int relinvCnt=Resrelinv.getItemCount(); // return inn.newError(relinvCnt.ToString()); decimal AmtTotal=0; decimal IgstTotal=0; decimal CgstTotal=0; decimal SgstTotal=0; decimal tTotal=0; for(int i=0;i<relinvCnt;i++) { Item iInv=Resrelinv.getItemByIndex(i); //get invoice relation property string amount=iInv.getProperty("bal_amount"); string igstamount=iInv.getProperty("bal_igstamt"); string cgstamount=iInv.getProperty("bal_cgstamt"); string sgstamount=iInv.getProperty("bal_sgstamt"); string totalamount=iInv.getProperty("bal_totalamt"); //get total of all relation property if(amount!=null) { AmtTotal=Convert.ToDecimal(AmtTotal)+Convert.ToDecimal(amount); } if(igstamount!=null) { IgstTotal=Convert.ToDecimal(IgstTotal)+Convert.ToDecimal(igstamount); } if(cgstamount!=null) { CgstTotal=Convert.ToDecimal(CgstTotal)+Convert.ToDecimal(cgstamount); } if(sgstamount!=null) { SgstTotal=Convert.ToDecimal(SgstTotal)+Convert.ToDecimal(sgstamount); } if(totalamount!=null) { tTotal=Convert.ToDecimal(tTotal)+Convert.ToDecimal(totalamount); } } decimal gtotal=Convert.ToDecimal(tTotal)+Convert.ToDecimal(transportAmt)+Convert.ToDecimal(cessAmt); // return inn.newError(AmtTotal.ToString()); //set calculated total to invoice this.setProperty("bal_taxablevalue",AmtTotal.ToString()); this.setProperty("bal_igstamount",IgstTotal.ToString()); this.setProperty("bal_cgstamount",CgstTotal.ToString()); this.setProperty("bal_sgstamount",SgstTotal.ToString()); this.setProperty("bal_totalamount",tTotal.ToString()); this.setProperty("bal_gross_total",gtotal.ToString()); i added this code on itemtype onAfterAdd and onAfterUpdate but i have to click on save button twice to update item form property to avoid this i adde code- if(this.getAction()!="add") { this.apply("update"); } but i get an error - item with same key alreay added please help me