locked
how to get URL to the entity in custom workflow code RRS feed

  • Question

  • I need to send several kinds of emails both on user demand and automatically in response to a user action. For example, I need for the recipient list to be the users with whom the owner has shared the entity, so I am using custom workflow activity classes to do this. However, I am not finding a way to get the URL to the entity (like Copy Link) in my C# code in my custom activity classes. Thanks.

    Tuesday, June 5, 2012 8:02 PM

Answers

  • Jim,

    What update rollup have you got? I've just checked that you need at least Update Rollup 5.

    If the dropdown is empty, you need to click on your Custom Workflow Activity Parameter before the dropdown gets populated.

    You'll also need to make sure that the InArgument is a type of string.

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.


    Dimaz Pramudya | CSG (Melbourne) | http://www.xrmbits.com | dimaz@xrmbits.com If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, June 6, 2012 2:51 AM

All replies

  • Jim,

    As of Update Rollup 6 (I think), Microsoft introduced the Record URL dynamic value which will return the URL to that record (similar to Copy Link function).

    What you can do is to pass this parameter to your custom workflow activity and use it from within your code.

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.


    Dimaz Pramudya | CSG (Melbourne) | http://www.xrmbits.com | dimaz@xrmbits.com If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, June 6, 2012 2:20 AM
  • Thanks, but the drop down where you show Record URL is empty for my custom entity.
    Wednesday, June 6, 2012 2:26 AM
  • Jim,

    What update rollup have you got? I've just checked that you need at least Update Rollup 5.

    If the dropdown is empty, you need to click on your Custom Workflow Activity Parameter before the dropdown gets populated.

    You'll also need to make sure that the InArgument is a type of string.

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.


    Dimaz Pramudya | CSG (Melbourne) | http://www.xrmbits.com | dimaz@xrmbits.com If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, June 6, 2012 2:51 AM
  • Hi Jim, you can also generate the URL from within your custom workflow activity, but you need to hardcode somewhere the server name, since it is not possible to retrieve the server name from a custom workflow activity.

    You can also use the Crm2011WorkflowUtilities, there is a custom workflow activity that will give you the hyperlink to any entity in the system:

    http://crm2011workflowutils.codeplex.com/


    Gonzalo | gonzaloruizcrm.blogspot.com

    Wednesday, June 6, 2012 1:36 PM
    Moderator
  • Hello Jim Hammond:

    By using this code, you will get the base url of the record.

    HttpContext webContext = HttpContext.Current;

    if (webContext != null)
    {
    string url = webContext.Request.Path;
    }

    Now as you are worried that how to get entity code, record ID and construct the url,

    so for your information, we can replace entity code with entity name

    so just use 'etn=entityname' in place of'etc=entitycode'

    Entity name you can get from currentContext.EntityName

    Now, you need current record Id, that you can get from currentContext.PrimaryEntityID.

    You have now all the things to construct a record URL without hard-coding anything.

    This is tested and working fine....so if you have any confusion in implementing this, let me know.

    Enjoy...:)


    Saurabh Gupta, MS CRM 2011 Software Development Engineer

    Wednesday, June 6, 2012 6:36 PM
  • I added a reference to System.Web to try this technique, and the value in HttpContext.Current.Request.Path is "/".
    Wednesday, June 6, 2012 11:33 PM
  • I don't think there is an HttpContext in AsyncService, that's why I mentioned you cannot retrieve the server name from a custom workflow activity.

    Gonzalo | gonzaloruizcrm.blogspot.com

    Thursday, June 7, 2012 12:47 AM
    Moderator
  • Thanks! Your reply contained enough hints that I eventually figured it out.

    I had never used InArgument before. That code is here:

            [Input("Special Case URL")]
            [ReferenceTarget("new_specialcase")]
            public InArgument<string> CaseUrl { get; set; }
    

    After that, "Special Case URL" appeared in the dialog that pops up when you click on "Set Properties" for your workflow step.

    I had to stop all instances of CrmAsyncService. I also recycled the CrmAppPool, but that may not be necessary.

    Thursday, June 7, 2012 1:15 AM
  • Hi Jim,

    Glad that worked. In some cases, you will need to recycle the AppPool and restart the AsyncService for the input parameter to come up.


    Dimaz Pramudya | CSG (Melbourne) | http://www.xrmbits.com | dimaz@xrmbits.com If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Thursday, June 7, 2012 1:20 AM