locked
Display the link to newly created record on Dialog RRS feed

  • Question

  • Hi, 

    I have created a new dialog which creates a new Account (exact copy of the selected account) in CRM 2011 and disable the selected account. Its working as desired.

    But on last page of the Dialog, I want to display the link to newly created record. Can anyone suggest me how I can achieve this.

    Thanks in advance



    Wednesday, June 12, 2013 2:04 PM

Answers

  • You could use something like that:

    [Output("Link:")]
    public OutArgument<string> Link { get; set; }
    
    protected override void Execute(CodeActivityContext context) {
      IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();
      IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
      IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);
    
      string AccountLink = "http://<server-name>/<organame>/main.aspx?etc=1&id=%7b<entityID>%7d&pagetype=entityrecord";
      string MachineName = Environment.MachineName;
      string OrganizationName = workflowContext.OrganizationName;
          
      Guid _accountID = service.Create(_newAccount);
    
      AccountLink = AccountLink.Replace("<server-name>",MachineName);
      AccountLink = AccountLink.Replace("<organame>",OrganizationName);
      AccountLink = AccountLink.Replace("<entityID>",_accountID.ToString());
    
      Link.Set(context,AccountLink);
    }

    I'm not sure if the hack with the server name works for you. Maybe you have to "hard code" it.

    Best regards

    Steve


    Steve Sämmang, Vienna, Austria
    Blog: xrm.io Website: simplic.at

    • Marked as answer by jattscorpion Thursday, June 13, 2013 1:06 PM
    Thursday, June 13, 2013 10:30 AM
  • [Output("LinkArgument ")]
    [ReferenceTarget(Account.EntityLogicalName)]
    public OutArgument<EntityReference> LinkArgument { get; set; }

    It worked for me after retuning the EntityReference of newly created account as a output parameter.

    Then added a new page and in the prompt used the "Insert Hyperlink". In the dropdown ("Look for") on the right site, selected the EntityReference of New Account. It gave me the option to select the URL.

    Thanks for your help Steve.


    • Marked as answer by jattscorpion Thursday, June 13, 2013 1:13 PM
    • Edited by jattscorpion Thursday, June 13, 2013 1:23 PM
    Thursday, June 13, 2013 1:13 PM

All replies

  • Hello,

    - create the Account via your dialog

    - insert a page

    - insert a reaction

    - in the prompt text, click the "Insert Hyperlink" button

    - in the URL field, select the Create(Account) entity in the drop-down

    - then "Record URL(Dynamic)" in the field selector

    Best regards,

    Steve

    Source: http://stackoverflow.com/questions/11316172/crm-2011-dialog-open-the-entity-created-in-a-dialog


    Steve Sämmang, Vienna, Austria
    Blog: xrm.io Website: simplic.at



    Wednesday, June 12, 2013 2:23 PM
  • Hi Steve, 

    thanks for your answer. 

    I tried the way you explained but the link is taking me to the selected account rather than newly created account.

    Do I need to return the new record as output argument?
    Thursday, June 13, 2013 7:59 AM
  • Hi,

    If you created the account through a dialog step "create entity", I guess you selected the wrong entity to show.

    After choosing "Insert Hyperlink" you'll find a dropdown ("Look for") on the right site. Choose the local Value "create (account)". Be sure you don't select the primary entity.


    It's the account entity on the bottom of the dropdown (Create(Account)).

    After that you can insert the record url(dynamic).

    Best regards

    Steve


    Steve Sämmang, Vienna, Austria
    Blog: xrm.io Website: simplic.at



    • Edited by saemmang Thursday, June 13, 2013 9:40 AM
    Thursday, June 13, 2013 9:00 AM
  • But if you created the account through a plugin you have to work with an output parameter like that:

    public class InitPaymentProcess:CodeActivity {
        [Output("Link:")]
        public OutArgument<string> Link { get; set; }
    
    .......

    and set it this way:

    Link.Set(context,"LinkToEntity");

    Best regards

    Steve


    Steve Sämmang, Vienna, Austria
    Blog: xrm.io Website: simplic.at

    Thursday, June 13, 2013 9:03 AM
  • HI Steve, 

    Yes I am creating contact through workflow activity. Can you please explain me how I can retrieve the link in code to pass it back as output parameter?

    Thanks

    Thursday, June 13, 2013 10:17 AM
  • You could use something like that:

    [Output("Link:")]
    public OutArgument<string> Link { get; set; }
    
    protected override void Execute(CodeActivityContext context) {
      IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();
      IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
      IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);
    
      string AccountLink = "http://<server-name>/<organame>/main.aspx?etc=1&id=%7b<entityID>%7d&pagetype=entityrecord";
      string MachineName = Environment.MachineName;
      string OrganizationName = workflowContext.OrganizationName;
          
      Guid _accountID = service.Create(_newAccount);
    
      AccountLink = AccountLink.Replace("<server-name>",MachineName);
      AccountLink = AccountLink.Replace("<organame>",OrganizationName);
      AccountLink = AccountLink.Replace("<entityID>",_accountID.ToString());
    
      Link.Set(context,AccountLink);
    }

    I'm not sure if the hack with the server name works for you. Maybe you have to "hard code" it.

    Best regards

    Steve


    Steve Sämmang, Vienna, Austria
    Blog: xrm.io Website: simplic.at

    • Marked as answer by jattscorpion Thursday, June 13, 2013 1:06 PM
    Thursday, June 13, 2013 10:30 AM
  • [Output("LinkArgument ")]
    [ReferenceTarget(Account.EntityLogicalName)]
    public OutArgument<EntityReference> LinkArgument { get; set; }

    It worked for me after retuning the EntityReference of newly created account as a output parameter.

    Then added a new page and in the prompt used the "Insert Hyperlink". In the dropdown ("Look for") on the right site, selected the EntityReference of New Account. It gave me the option to select the URL.

    Thanks for your help Steve.


    • Marked as answer by jattscorpion Thursday, June 13, 2013 1:13 PM
    • Edited by jattscorpion Thursday, June 13, 2013 1:23 PM
    Thursday, June 13, 2013 1:13 PM
  • Oh ok. Why I made it so complicated :)

    Great


    Steve Sämmang, Vienna, Austria
    Blog: xrm.io Website: simplic.at

    Thursday, June 13, 2013 1:15 PM