This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Get and set integer property value as integer

ergr - Thursday, April 10, 2014 10:04 AM:

Hi,

My ItemType has some 'integer' data type properties, but in server method(c#) I am not able to get the Integer Property value as int using getProperty().

int qua = this.getProperty("quantity"); This says Cannot implicitly convert type 'string' to 'int'

And same thing happening while setting an integer value to an integer property.

this.setProperty("rem_qua",4); This says Cannot implicitly convert type 'int' to 'string'

How to do this. Am I need to use Conversion methods always? If I use Convert.ToString(4) to set value,  I am not seeing correct values set. Please help me

 

Thank you,



zahar - Thursday, April 10, 2014 10:10 AM:

Int qty;

int.TryParse(this.getProperty("quantity", "0"), out qty);

 

 



ergr - Friday, April 11, 2014 4:30 AM:

Thanks Zahar,

Your solution is working well on new Item creation/update manually. I have another Item type with a life cycle, and a method added to one transition's 'Post' to update the Parent Item and set new value to quantity. At this time 'qty' is returning null.

Itemtype1- OnBeforeAdd, OnBeforeUpdate

Innovator inn= this.getInnovator();
int qty1,qty2;
int.TryParse(this.getProperty("quantity", "0"), out qty1);
int.TryParse(this.getProperty("quantity_lo", "0"), out qty2);
if(qty1==0 || qty1<qty2)
return inn.newError("Enter Valid number in Quantity");

ItemType-2- LifeCycle Transition's Post:

Innovator inn= this.getInnovator();

int qty_umr;
int.TryParse(this.getProperty("quantity_umr", "0"), qty_umr);

Item num = this.getPropertyItem("parent_item");
Item ParentItem = inn.newItem("Parent","edit");
        ParentItem.setAttribute("where","[PARENT].id = '"+num.getID()+"' ");

int qty1;
int.TryParse(ParentItem.getProperty("quantity", "0"), out qty1);
int new_qty = qty1-qty_umr;
ParentItem.setProperty("qty1",Convert.ToString(new_qty));
ParentItem = ParentItem.apply();

After Promoting the Item I am getting the Error 'Enter Valid number in Quantity'. Item has Quantity as 9,Quantity LO as 4, but 'qty1' getting null value. I used inn.newError("Quantity"+qty1) to check what it is getting. Even returning null of 'qty2' also.


This is happening only when I try to update the item though the above code after Promotion. Showing correct values on manual update.  How to solve this?



zahar - Friday, April 11, 2014 5:27 AM:

After actions usually don't  contains any information except ID + ITEM TYPE.

What you need to do is to get databased on ID+TYPE and then process with your code

Item thisItem = this.getInnovator().getItemById(this.getType(), this.getID());

if (!thisItem.isError()) {

// USE "thisItem" instead 'this"

}

return this;

 

I think you have problem in this code, you need to use "num" object in TryParse and not ParentItem - because ParentItem is not yet executed against the server:

Item ParentItem = inn.newItem("Parent","edit");
ParentItem.setAttribute("where","[PARENT].id = '"+num.getID()+"' ");

 

 

int qty1;
int.TryParse(ParentItem.getProperty("quantity", "0"), out qty1);



ergr - Monday, April 14, 2014 1:12 AM:

Thank you very much Zahar.