Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

on demand workflow

(0) ShareShare
ReportReport
Posted on by

Hi Friends

Can you please help me to create on demand custom workflow.

This should run once everyday on demand.

*This post is locked for comments

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: on demand workflow

    Hi Suchisuchi,

    You could refer the below code to retrieve the root account reference by passing the main account. This is built in console application but you should be able to use the same code in plugin or custom workflow activity.

            public void UpdateAccountParent()
            {
                using (service = new OrganizationServiceProxy(new Uri(_organizationURI), null, _credential, null))
                {
                    var entityId = new Guid("E32B12C4-7F95-E811-A961-000D3AE05E81");
                    var entityName = "account";
                    var mainAccount = SearchHelper.RetrieveSingle(service, entityName, entityId);
    
                    // Get the root accoutn reference
                    EntityReference rootAccountRef = null;
                    GetRootAccount(service, mainAccount.ToEntityReference(), out rootAccountRef);
    
                    // If root account ref is null that means there is no parent account, displaying the name from the main account
                    if (rootAccountRef != null)
                    {
                        var rootAccount = service.Retrieve(rootAccountRef.LogicalName, rootAccountRef.Id, new ColumnSet(true));
                        Console.WriteLine(rootAccount["name"]);
                    }
                    else
                    {
                        Console.WriteLine(mainAccount["name"]);
                    }
                }
            }
    
            public void GetRootAccount(IOrganizationService service, EntityReference accountRef, out EntityReference rootAccount)
            {
                rootAccount = null;
                // Check if the account has parent
                var accoutnRecord = service.Retrieve(accountRef.LogicalName, accountRef.Id, new ColumnSet(true));
                if (accoutnRecord.Contains("parentaccountid"))
                {
                    var parentAccountRef = (EntityReference)accoutnRecord["parentaccountid"];
                    GetRootAccount(service, parentAccountRef, out rootAccount);
                }
                else
                {
                    rootAccount = accountRef;
                }
            }


    Hope this helps.

  • Suggested answer
    Ben Thompson Profile Picture
    Ben Thompson 6,350 on at
    RE: on demand workflow

    You can't schedule a workflow within Dynamics 365 but you can do it within a Microsoft flow  thatcrmblog.wordpress.com/.../scheduling-workflows-with-microsoft-flow will show you how to do that and also how to update a records from within that flow...

  • RE: on demand workflow

    I dont need plugin but custom workflow that will be calling the on demand workflow..

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: on demand workflow

    Further more, you don't even need a plugin to update the fields, you could achie this in out of box workflow (real time)

  • RE: on demand workflow

    oh Ok, let me try the suggestion then, and will update. Thanks Ravi

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: on demand workflow

    Hi Suchisuchi,

    The logic to update the records should be same as mentioned community.dynamics.com/.../289465

    What exactly you are looking for?

    Also, as mentioned above, you don't need to run it daily on the modified account, you can simply update the record when the account update. Is there something more to this requirement?

    Hope this helps.

  • RE: on demand workflow

    Hi Ravi, It is actual requirement this time :(

    Account Name: Account A

    PAL: PAL A

    ParentAccount Id= Account  B

    Account Name: Account B

    PAL: PAL B

    ParentAccount Id= PAL C

    Account Name: Account C

    PAL: PAL C

    ParentAccount Id=

    In this example, Account A's Parent account is "Account B" and "Account B's" parent is "Account C". Acccount C does not have a parentAccount Id so it is the top level Account for Account A and Account B.

    So for Account A, aac_toplevepal= PAL C and aac_toplevelpalname=Account C

    So for Account B, aac_toplevepal= PAL C and aac_toplevelpalname=Account C

    So for Account C, aac_toplevepal= PAL C and aac_toplevelpalname=Account C

    We have to run this workflow everynight once a day. It should get all accounts that were modified yesterday and update their xcv_toplevelpal and xcv_toplevelpalname using the above logic.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: on demand workflow

    Hi Suchisuchi,

    Could you please share your requirement in more detail? Is this an actual requirement or you want to learn more about custom workflows?

    If you want to update the parent account name to another field on the account record then you don't need a custom workflow and certainly you don't need to run it on daily basis. You could simply write a real time workflow which triggers on update and the retrieves the parent account name and populate your field.

    Hope this helps.

  • RE: on demand workflow

    27362.Untitled.png

    Here it is re-uploaded

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 1,019 Super User 2025 Season 1 on at
    RE: on demand workflow

    Hi Suchisuchi,

    Please reupload the image.png file.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

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,436 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans