Forum Discussion

team_aras_meupe_com's avatar
2 years ago

onBeforePromote: how to take the id value?

Hello, I have created a method in c#, in which I take the ID value and do some things.

The fact is that if I put the method in onBeforePromote, it gets a null value, I have tried it in 3 possible ways. The strange thing is that if I put that method in another event, like , it takes the ID value correctly.

[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:1af81f66-239a-4c84-8147-bcb145917235:type=csharp&text=Innovator%20innovator%20%3D%20this.getInnovator%28%29%3B%0A%0Avar%20id%3Dthis.getID%28%29%3B%0Avar%20OrdenID1%20%3D%20this.getProperty%28%22id%22%29%3B%0Avar%20OrdenID2%20%3D%20document.thisItem.getProperty%28%22id%22%29%3B%0A%0A%2F%2Fvar%20OrdenID%20%3D%20this.getProperty%28%22id%22%29%3B%0A%0A%2F%2Fstring%20StateOF%20%3D%20this.getProperty%28%22state%22%2C%22%22%29%3B%0A%2F%2Fstring%20EstadoOF%20%3D%20this.getProperty%28%22estado_cv%22%2C%22%22%29%3B%0A%0Areturn%20innovator.newError%28%22AA%20%22%20%2B%20id%20%2B%20%22BB%20%22%2BOrdenID1%20%2B%20%22CC%20%22%2B%20OrdenID2%29%3B%0A]

1 Reply

  • Hi,

    there is not id when using onBeforePromote. Throw an error message just with "this" and you will see. 

    It only contains an idlist:

    Innovator inn = this.getInnovator();

    // Get the Items(s) affected by this promotion
    string idlist = this.getAttribute("idlist");

    // Get items by idlist
    Item xy= inn.newItem("xy", "get");
    xy.setAttribute("idlist", idlist);
    xy.setAttribute("select","xy");
    xy= xy.apply();

    // Prevent execution of code if more than one items was selected (if you want this behavior...)
    int itemCount = xy.getItemCount();
    if (itemCount > 1)
    {
      return inn.newError("This action only works for one item...");
    }

    onBeforePromote is not my favourite kind of event. If you can achieve the same behavior with a LifeCycle pre Method, better use this one!

    Bye

    Angela