How to add History using a custom method?

I want to log in History when a specific "Action" is performed on a "Part" . I try to do this by adding to the "History" table. I do get a response that the record is added, However, I do not see a record in the database, neither visible in the History View. I try to do this by invoking "History Daemon" identity.

How can i achieve this in Aras?

<AML>
<Item action='add' type='History'>
<action>Special Action</action>
<source_id>#######ITEM HISTORY CONTAINER ID#############/source_id>
<comments>Attempted Special Action</comments>
<item_id>#######ITEM ID##############</item_id>
</Item>
</AML>




Parents
  • I don´t want to take over this thread, but I have made a quick test today and maybe this helps. I want to create a generic Method that I can reuse in various other Methods to track certain events. E.g. I want to track when user started certain tasks from Form elements or Actions. 

    This one worked for me. Record is visible in History view. Used Innovator version is 11SP15.

    string id = this.getProperty("id");
    string configId = this.getProperty("config_id");
    string type = this.getType();


    // Grant 'Aras PLM' permissions
    Aras.Server.Security.Identity plmIdentity = Aras.Server.Security.Identity.GetByName("History Daemon");
    bool PermissionWasSet = Aras.Server.Security.Permissions.GrantIdentity(plmIdentity);

    try
    {
    // Get History container
    Item container = inn.newItem("History Container","get");
    container.setAttribute("select","id");
    container.setProperty("item_config_id",configId);
    container.setProperty("itemtype_id",type); // Part
    container = container.apply();
    string containerId = container.getItemByIndex(0).getID();

    // Add new History entry
    Item history = inn.newItem("History","add");
    history.setAttribute("doGetItem", "0");
    history.setProperty("source_id", containerId);
    history.setProperty("action", "Custom Action");
    history.setProperty("comments", "Custom Action was performed");
    history.setProperty("item_id", id);
    history.setProperty("created_on_tick", DateTime.UtcNow.Ticks.ToString()); // important for sort_order of history, but not necessary!
    history = history.apply();
    if (history.isError())
    {
    return inn.newError("An error occured: " + history.getErrorDetail() );
    }
    return this;
    }
    finally
    {
    // Revoke 'Aras PLM' permissions
    if (PermissionWasSet)
    Aras.Server.Security.Permissions.RevokeIdentity(plmIdentity);
    }

    Remarks: 

    - When I added the 'Super User' or 'Aras PLM' to the 'History Daemon' identity, I still wasn´t able to add a new History entry. I finally decided to directly use the History Daemon.
    DateTime.UtcNow.Ticks.ToString() that I used for created_on_tick is based on an Aras code sample (Method 'VC_PopulateAndAddSecureMessage')
    - There are still some properties missing. The current sample doesn´t set the revision properties that are used in the History

    I wonder if the same can be achieved more easily. Writing a history entry is no exotic task. Isn´t there some Aras Method available that we can reuse?

  • Hi Angelalp,

    thanks for the code. I agree this should be a standard API function. Indeed, we also get customers requests to make some important action visible in the history, which not necessarily is a standard action.

    Best regards,

    Raoul

  • BTW, in your code you push the type name (getType()) into the itemtype_id which obviously does not work. Luckily, you don't need the type to get the history container (id should be unique). So when you just omit this in the search, the code works.

  • Hi Raoul,

    thanks for the hint! You´re right, with the itemtype_id. The above query isn´t perfect. I noticed that I use two AML queries. I use a get/add combination. it would be better to unify these two into an edit/add query.

    But is the config_id really unique over all ItemTypes? Or just within one table? 

Reply
  • Hi Raoul,

    thanks for the hint! You´re right, with the itemtype_id. The above query isn´t perfect. I noticed that I use two AML queries. I use a get/add combination. it would be better to unify these two into an edit/add query.

    But is the config_id really unique over all ItemTypes? Or just within one table? 

Children
No Data