Setting properties using results from dialog

オフライン

I'm having problems updating an item property using a method that opens a custom dialog. I opened a dialog following the ArasModules.dialog example from https://community.aras.com/b/english/posts/tech-tip-opening-a-custom-dialog-from-a-method, the dialog opens to a form where the user can select an item from a list which is returned in the "res" value of the callback function. Once there, I wanted to set the property of an item to this value, but it seems like i lost the original context item and innovator object after opening the dialog. When I debug in the browser the "this" item is of the [object window] type. The results contain two id strings, and I'm trying to use them to set an "item" property.

I tried defining a new innovator object and setting the property but I can't get it to actually apply the changes.

function callback(res) {
 if (res) {
    var id_1 = res[0];
    var id_2 = res[1];

    var inn = new Innovator();
    var item_2 = inn.newItem("MyItemType","edit");
    item_2.setID(id_2);
    item_2.setAttribute("select","MyProperty");
    item_2.setProperty("MyPropertyl",id_1);
    item_2.apply();
 }
}

How can I set the property from this context?

/Rick

  • Hello,

    You can temporarily store the value of this inside of another variable before you open your dialog. This should allow you to access it inside of your callback after the dialog returns.

    // Store the value of the context item
    var self = this;
    wnd.ArasModules.Dialog.show('iframe', param).promise.then(callback);

    After this, you can access the context item in your callback through the variable you've defined instead of this.

     function callback(res) {
     if (res) {
        var id_1 = res[0];
        var id_2 = res[1];

        self.setProperty("MyProperty", id_1);
        self.apply();
     }
    }

    As an additional note, you almost never need to define a new Innovator object inside of a Method. From a client-side method, you can access an Innovator object from most contexts by using aras.IomInnovator. This admittedly shouldn't have any impact on functionality, but it's slightly more memory efficient to reference the existing object. 

    Chris

    Christopher Gillis

    Aras Labs Software Engineer

  • How do I bring the "self" variable back after the dialog returns? When i set a debugger statement in the callback function and check what variables I have, I can't find the variables from before the dialog was called. My action and method are acting on a relationship item, and it seems like the context after the dialog is the parent item of the relationship instead of the relationship item which is the context before the dialog is opened.

    I had some success with aras.IomInnovator, I used:

    function callback(res) {
     if (res) {
        var sel_id = res[0];
        var rel_id = res[1];
        var inn = aras.IomInnovator;
        var rel_item = inn.getItemById("RelationshipItemtype",rel_id);
        var sel_item = inn.getItemById("RelatedItemtype",sel_id);
        rel_item.setProperty("related_item_property",sel_item);
        rel_item.apply();
     }
    }

    I can see that rel_item and sel_item are successfully defined in the debugging mode, but the property isn't being updated.

  • 0 オフライン in reply to RickP

    It actually seems to be working now! I just didn't realize since the relationship grid didn't update to show it until I did an empty search, I guess I just need to figure out how to make the method run an empty search as well.

  • Hi Rick,

    You can take advantage of another function of the aras object to refresh the grid. You can call aras.uiReShowItem(item_id, item_id); in order to refresh the parent item. Since you said that the this variable seems to be referencing the parent item in the callback, you might be able to accomplish this refresh like so:

    aras.uiReShowItem(this.getAttribute("id"), this.getAttribute("id"));

    Note that this will depend on what the actual value of this is.

    In regards to your question about referencing the self variable, I was able to reference this variable just by calling self inside of the callback. This was a test I ran in 11.0 SP15 using the ArasModules.Dialog.show function. This variable reference might be different if you are using another version of Aras Innovator or a different function for opening your dialog.

    Chris

  • I'm on v11 SP12 so maybe it's different, the window is being called like this:

    var topWnd = top.aras.getMostTopWindowWithAras();
    var wnd = topWnd ? topWnd : window;
    wnd.ArasModules.Dialog.show('iframe', param).promise.then(callback);

    Thanks for the help anyways!