none
CRM 4.0 Links to Entities in Workflow Email RRS feed

  • 问题

  • 这是我在解决CRM中,Email内包含“直接访问链接”的问题时,发现的一个好帖子。
    转载自 http://www.eggheadcafe.com/conversation.aspx?messageid=33043911&threadid=31527000
    希望对大家会有所帮助。

    Many times we would like to include an HTML link in an email notification sent to user. Sometimes we could just use ‘Regarding’ field of email, but this only works if user uses Outlook Client and even then, email tagging may take a while and ‘View Regarding’ button is not available when user actually reads the email. In addition, we may want to have one entity as Regarding and another as additional link.

    It does not sound very difficult, at least that is what I thought first time I encountered this requirement. I figured I could just use the GUID of the record to give user link in format of:

    http://CRM/sfa/accts/edit.aspx?id={GUID}

    As it turns out, the GUID is not available for workflows.  With some searching, I found similar issues dating back to CRM 3.0 and some approaches that saved the GUID or the full link to a custom field if the Form is Update Form.

    The obvious downside of this is that when a new record is created, it will not have value for the custom field unless  the user opens up the form again after saving it. This was not enough for me, but it was the starting point for my solution:

    • When user initiates save on new record, intercept and cancel that save
    • Force Saving the record in order for GUID be generated, reload form and set the GUID to custom attribute
    • Continue User Initiated save
    • The main challenge is to able to handle any kind of save: Save, Save and New, Save and Close.

    Actual Solution

    • Create a custom attribute of type nvarchar to hold the GUID or URL. Add this field in form. In my case, I elected to save only the GUID, in order to have the ability to re-use the GUID for possible other purposes late on. I call the field po_workflowguid.
    • Add following logic to OnSave Event:  
    //ONSAVE
    //If we already have value in field, skip this logic
    if ((crmForm.all.po_workflowguid.DataValue == null )
     ||(crmForm.all.po_workflowguid.DataValue==""))
    {
     //Set temporary flag on the GUID field, based on which save was called.
     //This is important so we know which event to continue.
     if (event.Mode==2)
      crmForm.all.po_workflowguid.DataValue="SAVEANDCLOSE";
     else if (event.Mode==59)
      crmForm.all.po_workflowguid.DataValue="SAVEANDNEW";
     else
      crmForm.all.po_workflowguid.DataValue="SAVE";
     //Force Form to save, in order to create GUID and re-load the form.
     crmForm.Save();

     //Abort the original Save
     event.returnValue=false;
     return false;
    }
    • Add following logic to Onload Event. 
      
    //ONLOAD
    //Lets hide the field
    crmForm.all.po_workflowguid_c.style.display='none';
    crmForm.all.po_workflowguid_d.style.display='none';
    //Only process for Update Form
    if(crmForm.FormType == 2)
    {
     //If this is Update Form, we can simply set the GUID
     if ((crmForm.all.po_workflowguid.DataValue == null )
       ||(crmForm.all.po_workflowguid.DataValue==""))
      crmForm.all.po_workflowguid.DataValue=crmForm.ObjectId;
     else
     {
      //The Additional logic: Check for flag in GUID field
      //We will set the GUID and continue the type of save user initiated
      switch(crmForm.all.po_workflowguid.DataValue)
      {
       case "SAVEANDCLOSE":
        crmForm.all.po_workflowguid.DataValue=crmForm.ObjectId;
        crmForm.SaveAndClose();
       break
       case "SAVE":
        crmForm.all.po_workflowguid.DataValue=crmForm.ObjectId;
        crmForm.Save();
       break
       case "SAVEANDNEW":
        crmForm.all.po_workflowguid.DataValue=crmForm.ObjectId;
        crmForm.SubmitCrmForm(59, true, true, false);
       break
       default:
       break
      }
     }
    }
    • Now you can use the po_workflowguid field to add links to Workflow Emails

    Workflowguid Link

    The downside of this approach is that when user saves the form for the first time, they will see a brief flicker from form loading twice.

    Another way to achieve this functionality would be to write a custom Plugin for retrieving the GUID of entity and just using that in the workflow.

    2009年6月3日 2:44

答案