Getproperty() function returns only Null Value

オフライン

Hello,

I am facing an issue while developing a server side C# method. My method supposed to pull up all the Manufacturer Parts from the table and iterate through them checking them for a condition. If the condition is met, it should return an error.

I was able to retrieve the Manufacturer Part list and iterate over them. However when I am trying to get the value of a property of the Manufacturer Part, it always returns Null.

***********************************************************************************************

Item Man_Part_List = inn.newItem("Manufacturer Part");
Man_Part_List.setAttribute("where", "[Manufacturer_Part].IS_CURRENT= '1'");
Man_Part_List = Man_Part_List.apply();


for (int i = 0; i < Man_Part_List.getItemCount(); i++)
{
    
   Item cur_man_part = Man_Part_List.getItemByIndex(i);
   string cur_man_part_name = cur_man_part.getProperty("item_number");       //cur_man_part_name always returns NULL

   if (cur_man_part_name == part_number)
   {
    return this.getInnovator().newError("Manufacturer Part with same name already exist" );
    count = count + 1;
   }
   
 }

***********************************************************************************************

Thanks,

NC.

Parents
  • I assume you just get the very plain items without properties. Use the "get" command and combine it with and combine it with a "select" to reduce server load.

    Item Man_Part_List = inn.newItem("Manufacturer Part","get");
    Man_Part_List.setAttribute("select","item_number");

    ---

    You liked this answer? Subscribe to my Youtube channel to learn even more about PLM --> PLM Underground on Youtube

  • 0 オフライン in reply to AngelaIp

    Changed the code use "get' command and combined it with "Select". Still didn't worked.

    Item Man_Part_List = inn.newItem("Manufacturer Part", "get");
    Man_Part_List.setAttribute("select","item_number");
    Man_Part_List.setAttribute("where", "[Manufacturer_Part].IS_CURRENT= '1'");
    Man_Part_List = Man_Part_List.apply();

  • It should work. I was able to use this one successfully in my test db:

    Innovator inn = this.getInnovator();

    Item Man_Part_List = inn.newItem("Manufacturer Part", "get");
    Man_Part_List.setAttribute("select","item_number");
    Man_Part_List.setAttribute("where", "[Manufacturer_Part].IS_CURRENT= '1'");
    Man_Part_List = Man_Part_List.apply();


    for (int i = 0; i < Man_Part_List.getItemCount(); i++)
    {

    Item cur_man_part = Man_Part_List.getItemByIndex(i);
    string cur_man_part_name = cur_man_part.getProperty("item_number"); //cur_man_part_name always returns NULL
    return inn.newResult("My test result: " + cur_man_part_name);

    }

    ---

    You liked this answer? Subscribe to my Youtube channel to learn even more about PLM --> PLM Underground on Youtube

  • 0 オフライン in reply to AngelaIp

    It is weird. I used the same code on my environment and for me it returns NULL.The only change is, am using newError instead of newResult but that should not make any difference.

    return inn.newError("My test result: " + cur_man_part_name1);

Reply Children
  • That´s really weird. Does your "getItemCount()" return the correct number items?

    What result do you get, when you directly display the item in an error message?

    E.g. 

    Innovator inn = this.getInnovator();

    Item Man_Part_List = inn.newItem("Manufacturer Part", "get");
    Man_Part_List.setAttribute("select","item_number");
    Man_Part_List.setAttribute("where", "[Manufacturer_Part].IS_CURRENT= '1'");
    Man_Part_List = Man_Part_List.apply();
    return inn.newError(" " + Man_Part_List);

    I am little bit confused of your 'where' query. It´s not wrong and should work, I am just curious why you use it. Manufacturer Parts by default are not revised.  What happens when you don´t use this filter or replace it with this version, that does the same:

    Man_Part_List.setProperty("IS_CURRENT","1");

    Is your query part of a bigger query? So for example you also search for Parts and Part AML at the same time? 

  • 0 オフライン in reply to AngelaIp

    Thanks for helping me on this. Here are my comments.

    1) Does your "getItemCount()" return the correct number items?  -- Yes

    2) What result do you get, when you directly display the item in an error message? - Attached the screenshot

    3) What happens when you don´t use this filter or replace it with this version, that does the same:Man_Part_List.setProperty("IS_CURRENT","1"); -- Tried it. But the results are same. It will still not give any name of the ManufacturerPart - Attached the screenshot. We have changed out Manufacturer parts to have revisions.

    4) Is your query part of a bigger query? So for example you also search for Parts and Part AML at the same time?  ---No

    Thanks,

    NC.

  • It doesn´t make any sense, there are no errors.

    1. Is the additional '1' a typo? return inn.newError("My test result: " + cur_man_part_name1);

    2. Do you see the result "placeholder" when providing placeholder value like:

    string cur_man_part_name = cur_man_part.getProperty("item_number","placeholder");

    3. You can try using xpath, also it´s not necessary:

    Item cur_man_part = Man_Part_List.getItemsByXPath("//Item[@type='Manufacturer Part']").getItemByIndex(i);