ashhadvv - Tuesday, January 25, 2011 9:11 AM:
The following code is a javascript method calling at the cell event of 'Estimated Cost' under Part->Goal->Cost on action 'onEdit Finish'.
By using this method I want to copy the value of property 'estimated_value' of the Relationship 'Part Goal' to property 'test' of Item Type 'Part'.
For an existing part after running this method and try to 'save,unlock,close' the part, it will show an error like 'The Part is not Locked by You'
Here the code,
var val = gridApplet.GetCellValue(relationshipID, colNumber);
var relItem = parent.thisItem.getItemsByXpath("//Item[@id='" +relationshipID + "']");
var estimatedCost = relItem.getProperty("estimated_value");
var sourceId = relItem.getProperty("source_id");
var myItem = parent.Item("Part","get");
myItem.setProperty('id',sourceId);
var result = myItem.apply();
var count = result.getItemCount();
for (var i=0; i<count; ++i)
{
var item = result.getItemByIndex(i);
var myId = item.getID();
var AML1='<AML><Item type="Part" action="edit" id="';
var id = myId;
var AML2 = AML1+id;
var AML3 = '"><test>'+estimatedCost;
var AML4 = AML2+AML3;
var AML5 = '</test></Item></AML>';
var AML = AML4+AML5;
var aml_result = top.aras.applyAML(AML);
}
Please give me a solution to remove this error
Brian - Friday, January 28, 2011 10:32 PM:
Hi Ashhadvv,
The problem you are seeing is because the Part item locked by you and then you are editing it in code. Since the Part item is Versionable the Edit that you do in code is creating a new "Generation" of the Part which is not locked.
So if you have a Part XXX at Rev A Generation 1 open for editing (and therefore locked) and you add a Part Goal to it and your method executes then there will also exist a Part XXX at Rev A Generation 2 that will include the updated part cost but you won't be able to close the Generation 1 part form correctly.
On top of this the "cost" field is used by Innovator to Roll Up the cost of child parts rather than for display of the actual cost for a part. Have a look at the Server Methods attached to Part and you will see the cost being replaced by a rolled up cost before it is displayed to the user.
I you want to put your own cost in there then you probably need to add your own field and then do the cost calculation in an "onBeforeAdd" or "onBeforeUpdate" server method that you attach to the Part Item Type.
This way the cost will be copied from the Goal when the item is saved and you will avoid the editing while you have the Part open for editing that you are doing now.
Cheers,
Brian.
ashhadvv - Monday, January 31, 2011 9:15 AM:
Thank you Brian..