locked
Plug-In Update on Child Entity needs to refresh Parent Entity RRS feed

  • Question

  • Hi Everybody, I've got a plug-in refresh problem that I just can't see a solution to.

    I have an entity that acts as a parent to another. On my parent are control totals from the children entities associated to it.
    When I create or update a child entity I run a Plug-In to calculate the new totals and record this on the parent.

    The problem I have is that the parent is still open, how do I go about forcing the parent to reload to get those update values.
    Or is there a better way to do this?

    Regards

    Steve
    Wednesday, May 13, 2009 8:20 AM

Answers

  • Hi, Steve.

    You can add such button changing ISV config. Look this article .
    Also there you can add the handler to button which will recalculate parent entity.

    To recalculate you can use following approaches:
    1. Read and modify entity parameters using Crm Web Services. Look article .
    2. Creating a custom 'system' webpage which will execute modyfiing the data.
    3. Creating a custom webservice which will execute such recalculation.

    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    Wednesday, May 13, 2009 11:06 AM
    Moderator

All replies

  • Hi, Steve.

    I have a idea how to do it.
    In OnLoad form handler remember the time of form opening.
    Using SetInterval add the timer handler which will retrieve ModifiedOn field of the record trough WebServices of MS CRM.
    Compare open date time and ModifiedOn datetime, if ModifiedOn greater then open date - call location.reload method. This will reload form of the opened record.
    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    Wednesday, May 13, 2009 8:49 AM
    Moderator
  • Is there a way to do a location.reload only when the child entity window is closed, and the focus returns to the parent?

    Regards
    Steve
    Wednesday, May 13, 2009 9:08 AM
  • Hi, Steve.

    I think it possible but in hard way and i don't know in what.

    But this doesn't solve the problem in situation when child entity form were updated from another computer.
    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    Wednesday, May 13, 2009 9:10 AM
    Moderator
  • Perhaps I'm going about this the wrong way.

    Instead of trying to force the parent to be updated when a child is created or changed, may be it would be best to have a 'Recalculate' button on the parent to get the latest details from all child records.

    Is it possible to call a DLL from a form menu action?

    Wednesday, May 13, 2009 9:54 AM
  • Hi, Steve.

    Your question was interested me, so i developed and tested a script you need. It made for contact form but you can change to any other form chaging entity name in request. Try it:

    function timerHandler() 
    {
    var xml = "<?xml version='1.0' encoding='utf-8'?>"+ 
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+ 
    GenerateAuthenticationHeader()+ 
    "<soap:Body>"+ 
    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+ 
    "<entityName>account</entityName>"+ 
    "<id>"+crmForm.ObjectId+"</id>"+ 
    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+ 
    "<q1:Attributes>"+ 
    "<q1:Attribute>modifiedon</q1:Attribute>"+ 
    "</q1:Attributes>"+ 
    "</columnSet>"+ 
    "</Retrieve>"+ 
    "</soap:Body>"+ 
    "</soap:Envelope>";
    //Prepare the xmlHttpObject and send the request.
    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);
    var resultXml = xHReq.responseXML;
    
    var source = resultXml.selectSingleNode("//q1:modifiedon").nodeTypedValue;
    
    var firstpart = source.split('T')[0];
    var secondpart = source.split('T')[1].split('+')[0];
    var parts =  firstpart .split('-');
    var parts2 = secondpart.split(':')
    
    var modifiedon = new Date();
    
    modifiedon.setYear(parts[0]);
    modifiedon.setMonth(parts[1] - 1);
    modifiedon.setDate(parts[2]);
    
    modifiedon.setHours(parts2[0]);
    modifiedon.setMinutes(parts2[1]);
    modifiedon.setSeconds(parts2[2]);
    
    if (modifiedon > openDate)
    location.reload();
    }
    
    var openDate = new Date();
    
    if (crmForm.FormType == 2)
    setInterval(timerHandler, 1000);

    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    Wednesday, May 13, 2009 9:56 AM
    Moderator
  • Perhaps I'm going about this the wrong way.

    Instead of trying to force the parent to be updated when a child is created or changed, may be it would be best to have a 'Recalculate' button on the parent to get the latest details from all child records.

    Is it possible to call a DLL from a form menu action?


    Steve, you are really on wright way. Child entity creation/update invokes parent entity update. So this update invoke modifiedon field change on parent entity. And my script detects it and executes form refresh.
    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    Wednesday, May 13, 2009 10:01 AM
    Moderator
  • If this is only a UI issue and you can get your hands on the child window object then it’s possible to bind to its “onunload” event and refresh the parent each time the child is reloaded.

     

    E.g.


    //parent form script

    window.child = window.open(‘child url’,’’,’’);

    window.child.attachEvent(“onunload”, recalculate);

     

    function recalculate(){
    location.reload();

    }


    Blog: http://mscrm4ever.blogspot.com/ * Website: http://gicrm.upsite.co.il/
    Wednesday, May 13, 2009 10:23 AM
  • Hi, Adi.

    This will not work if child window was called in usual way or for example in another computer.

    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    Wednesday, May 13, 2009 10:25 AM
    Moderator
  • The entities in question are a Timesheet Header and Timesheet Lines.

    It's not possible to create a timesheet line without going through the header first, so the header (parent) will always be open.
    As Timesheets are personal things I don't think the other computer will be an issue.

    Does that change things?

    For clarity, I've created a timesheet header that contains totals for each day of the week. As each line (in the child) is created I am totalling the total time and writing it back to the parent. As the parent is open it will show zero unless I can force a refresh/reload.

    I like the idea of a refresh button as well (like that on opportunities), but I'm not sure how to call a DLL from a form menu item.

    Regards

    Steve
    Wednesday, May 13, 2009 10:57 AM
  • If the calculation is made when the child is updated then the parent calculation button only needs to reload the page.


    Blog: http://mscrm4ever.blogspot.com/ * Website: http://gicrm.upsite.co.il/
    Wednesday, May 13, 2009 11:04 AM
  • Hi, Steve.

    You can add such button changing ISV config. Look this article .
    Also there you can add the handler to button which will recalculate parent entity.

    To recalculate you can use following approaches:
    1. Read and modify entity parameters using Crm Web Services. Look article .
    2. Creating a custom 'system' webpage which will execute modyfiing the data.
    3. Creating a custom webservice which will execute such recalculation.

    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    Wednesday, May 13, 2009 11:06 AM
    Moderator
  • Thanks Chaps

    I'll go through these articles and check them out, in the mean time I'll finish my plugin and give it a test.
    thanks

    Steve
    Wednesday, May 13, 2009 11:36 AM