Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Assigning GUID and a static url to two fields through custom workflow error

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

 I have created a plugin in which I want to embed a static url with the record guid. Initially, I want to check if the record guid is getting pulled. So I created two fields - "urllink" and "guidrecord" where I will store  the static url and record guid  My code is below. The fields are not getting populated. Any idea why?

There are no errors in the code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Microsoft.Xrm.Sdk.Workflow;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Query;

using System.Activities;

using Microsoft.Xrm.Sdk.Client;

using Microsoft.Crm.Sdk.Messages;

namespace wfpluginstest

{

   public class guidtofield : CodeActivity

   {

       protected override void Execute(CodeActivityContext executionContext)

       {

           //Create the context

           IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

           IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

           IOrganizationService _service = serviceFactory.CreateOrganizationService(context.UserId);

           if (context.PrimaryEntityName !== null)

           {

               Entity localdiscountfbapproval = new Entity("accountapproval");

               var guidofrecord= context.PrimaryEntityId;

               string staticurl = "http://test-rec:96/?id=&quot";

               localdiscountfbapproval["guidrecord"] = recordguid;

               localdiscountfbapproval["urllink"] = staticurl;

           }

       }

   }

}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Assigning GUID and a static url to two fields through custom workflow error

    Hey Alex,

    Sorry for the long post. Yes, next time I will break down the issue . Let's skip this one as I was able to solve it! ;)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Assigning GUID and a static url to two fields through custom workflow error

    Hi Ravi,

    Interesting thing is that it did not work.I tried that. For some reason, the workflow was not firing at all. That is why I had to resort to this method. Would it be because the account approval is setup as a child entity of account?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Assigning GUID and a static url to two fields through custom workflow error

    Hello guys,

    I was able to fix the issue. It was such a stupid issue. Purely my mistake. I was pulling the data from the second part of the

    workflow. Doing so, will obviously return empty because the records in the second part are not created yet!I got confused because of the stage names.

    They're almost exactly the same! Thanks a lot for your help guys!!

  • prt33k Profile Picture
    prt33k 6,907 on at
    RE: Assigning GUID and a static url to two fields through custom workflow error

    Thanks for the detail!

    So lets break it. The process flow is  :

    Account Create -> ((WF to Create AccountApproval ->( WF to Update Field)) -> Create Email to use Updated field in Prev Step)

    Current Behaviour : The child WF is updating the AccountApproval URL field but the email is getting created with blank field when referring to AccountApproval field.

    I wanted to understand how are you filling in the detail in Email entity. Is AccountApproval related to email? Also cant the email creation also be moved in the custom WF where you are updating the field?

    Logically, if you are having account approval related to email then the scenario should work. I did a simplistic run and I dont think the race condition can occur. 

    Prateek

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Assigning GUID and a static url to two fields through custom workflow error

    Hi Donald,

    If you have verified that the child workflow is updating the field value when executing on demand then it does look like that the child workflow is not executing  before the it used in the next steps.

    Why are you calling it as a child workflow? Wouldn't it work if you register on create of account approval record and trigger it real time (sync)?

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: Assigning GUID and a static url to two fields through custom workflow error

    Hi Donald,

     just my two cents here.. Could you split this problem into more than one question? If you have multiple workflows and they are not firing the way you want them to fire, figure that out first. Don't bring in the custom activity yet. Once that part is working, add the custom activity.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Assigning GUID and a static url to two fields through custom workflow error

    Hi Prateek,There are two workflows  related to this issue. The first workflow is the WF on the Account approval entity.

    I have now made this a child process and a real time workflow. The 2 steps in this workflow are executing the custom workflow activity plugin

    and updating a test field. I also made it an on demand process to test if the fields are getting updated.

    The second workflow on the account entity. It has two sets of steps. Both sets are almost the same. The only

    difference is the email being created. The content varies on the sets.I will explain how one set works. Initially it will check a flag in the entity and if

    it is true , will start executing the first set else, the second. In the first set there are 4 stages- check if business account and the corresponding email,

    coorporate account and corresponding email, merchant account and corresponding email, personal account and corresponding email. The business account stage is

    as follows. The "Check if businsss account approval" stage has two conditions. It will check a flag, if it evaluates to true, will create a new account

    approval entity record and the second step is to call the child workflow of the account approval entity which will update the three fields in that entity.

    The next step is the business account approval email. The issue is in the email. In the email, the data are not getting populated. I created a new field

    in the account approval called the Final URL which is of URL Text type. This field will store the concatenated URL. I search under the local values of the

    workflow and enter this field. It is returning empty. I  created a hyperlink with the URL being the field and that failed as well.

    Any idea why ? It is like as if the data is not getting updated fast enough from the previous step where the child WF is called and updating the fields.

    Note: The custom workflow assembly is doing what it is supposed to. I go to the account approval entity and the three fields are populated with the

    correct values.

    Account-Approval.PNGAccount-Approval.PNG

  • prt33k Profile Picture
    prt33k 6,907 on at
    RE: Assigning GUID and a static url to two fields through custom workflow error

    Your steps are correct.

    Can you share the screenshot of your Workflow Process page (the one on Create of AccountApproval) and also the custom workflow code.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Assigning GUID and a static url to two fields through custom workflow error

    Hi Prateek,

    Thanks for the response. The workflow is not firing. So, as mentioned earlier there are two entities- account and accountapproval. There is a on demand workflow registered on account entity which creates a record of accountapproval. So what I did was I created a new workflow registered on accountapproval entity. It fires when record is created. The only step of this workflow is to run this custom workflow activity plugin. For some reason it is not firing at all! Am I missing something?

  • Suggested answer
    prt33k Profile Picture
    prt33k 6,907 on at
    RE: Assigning GUID and a static url to two fields through custom workflow error

    Hi Donald,

    So you created a workflow with below code (Please note the change in creating Entity localdiscountfbapproval):

     protected override void Execute(CodeActivityContext executionContext)
           {
               //Create the context
               IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
               IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
               IOrganizationService _service = serviceFactory.CreateOrganizationService(context.UserId);
               if (context.PrimaryEntityName !== null)
               {
                   Entity localdiscountfbapproval = 
                   new Entity
                    {
                        LogicalName = "accountapproval",
                        Id = context.PrimaryEntityId
                    };
                   var guidofrecord= context.PrimaryEntityId;
                   string staticurl = "http://test-rec:96/?id=&amp;quot";
                   localdiscountfbapproval["guidrecord"] = recordguid;
                   localdiscountfbapproval["urllink"] = staticurl;
                   _service.Update(localdiscountfbapproval);
               }
           }


    If this is not working can you please check thew Audit if anything was updated and also the workflow status if that was triggered?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,317 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans