update a part's extended property through the iom

hello,

i have been able to update the extended property of a part through aml but i'm looking fo a sample code to understand how to do it with iom(innovator object model)

thanks,

Lucas

Parents
  • Hi Lucas

    Can you give a try using below code (Replace bold letters in below code)

    Innovator innovator = this.getInnovator();

    Item partEdit = innovator.newItem("Part", "edit");

    partEdit.setAttribute("id", "4F353307B92C40B5A9AADE4B1C857CDQ"); // Change with Part Item ID

    partEdit.setPropertyAttribute("xp-cost", "set", "value"); // Update the XProperty you want to update

    partEdit.setProperty("xp-cost", "100"); // Update the XProperty and its value

    partEdit = partEdit.apply();

    return partEdit;

    Thank You

    Gopikrishnan R

  • thank you very much,

    I am also having trouble getting an xproperty value from an item. i have an id of an item and want to get the value of some of its xproperties

    i've tried with getitembyID followed by a getproperty/getpropertyAttribute(Name of my x Property)

    but without success if you also have a sample code for that or where to look for it would really help.

    Lucas

  • Hi Lucas

    xProperties cannot be accessed similar to other properties in item. You need to run below query and then access the xProperties

    Item partGet = innovator.newItem("Part", "get");
    partGet.setAttribute("id", "4F353307B92C40B5A9AADE4B1C857CDQ"); // Change with Part Item ID
    partGet.setAttribute("select", "xp-*"); //change to specific xProperty
    partGet = partGet.apply();

    string xProp = partGet.getProperty("xp-cost")
    return partGet;

    Thanks

    Gopikrishnan R

  • hello

    thanks it is working well.

    i have a last question related to this topic, how do you create a new part with Xproperties programatically?

    Lucas.

Reply Children
  • Here is a sample code that creates  a new part and sets Xproperties values programatically for those interested:

    var inn = aras.IomInnovator;
    
    var part = inn.newItem("Part", "add");
    part.setProperty("name", "testing0" ) ;
    var Part_xclass= part.createRelationship("Part_xClass", "add");
    
    var xclass= Part_xclass.createRelatedItem("xClass", "get");
    
    xclass.setAttribute("select", "'id'");
    xclass.setProperty("name", "resistor" ) ;//your part's xclassname 
    part.setPropertyAttribute("xp-valeur_resistance", "set", "value"); // Update the XProperty you want to update
    part.setProperty("xp-valeur_resistance", "667"); //the value you want for the XProperty you want to update
    
    console.log("part before apply: "+part.ToString());//for debug purposes
    
    part = part.apply();
    if(part.isError()|| part.getItemCount() !== 1)
    {
        console.log("part error:"+part.getErrorDetail());
        return inn.newError(part.getErrorDetail());
    }
    else
    {
        alert(part.ToString());
        console.log("part after apply: "+part.ToString());
    }