Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Any way to tell/show when a background process is running?

Posted on by 3,079

Is there any hook in javscript to be able to show (in a notification, for example) when a record has a background process running on it?  We have a background process that takes some time to run (and doesn't always happen instantly), and afterwards it updates the record.  I'd like some way to notify any user looking at the record that the process is currently running, so the info is not yet up to date.

*This post is locked for comments

  • awalters Profile Picture
    awalters 3,079 on at
    RE: Any way to tell/show when a background process is running?

    Nothing as straightforward as I would have liked, certainly, but it never is.  :-)  Thanks for the ideas, both of you - we'll have to evaluate and figure out which way to go from here.

  • Verified answer
    Dipei Profile Picture
    Dipei on at
    RE: Any way to tell/show when a background process is running?

    You are right, SergiiChvyr. I was thinking a different use cases.

    If we have to get the "last" run system job for the current working entity, it is still doable. Here are the basic ideas:

    1. Create an attribute of DateTime: LastProcessStarted for the primary entity

    2. Add an extra step at the beginning of the process to set this attribute as Process.ExecutionTime

    3. Use the filters with criteria also contains: Process.startedon= {primary entity}.LastProcessStarted (we should use some additional criteria based on the real business logics)

    This should work. We can expect the return result set will be empty or a single record:

    1. Empty, that means the last process was succeeded

    2. Single record, it will contain the running status

    Thanks,

    Dipei

  • Verified answer
    SergiiChvyr Profile Picture
    SergiiChvyr on at
    RE: Any way to tell/show when a background process is running?

    Hi,

    What you really could do to achieve that, is to create your custom CodeActivity with boolean Output parameter to be used inside a workflow. This code activity should perform actions which were supposed to be performed inside your workflow.

    If you'll properly handle exceptions inside this code activity, then potentially you could set for example "true" to your output parameter if finished successfully, or "false" if there were any exceptions.

    After running this custom code activity, using check condition statement you could check the output parameter of the codeactivity and depending on the value, set appropriate status to the record.

  • awalters Profile Picture
    awalters 3,079 on at
    RE: Any way to tell/show when a background process is running?

    So there's no pre-existing functions for this, is what I'm hearing.  :-)  As a last attempt to keep this relatively straightforward, is there any way to set a field when a workflow fails?  Obviously setting one when it starts and when it finishes successfully is easy, but...  I wonder if we'd have more flexibility on that if we used an action instead - there seems to be more ability to get information returned from an action...

  • SergiiChvyr Profile Picture
    SergiiChvyr on at
    RE: Any way to tell/show when a background process is running?

    Imagine that you have one instance failed. Then, in some circumstances workflow runs again and finishes successfully. This successful workflow instance will be deleted. Thus, despite the fact that last was successful, you'll see it as failed.

    According to

    "Is there any way to set it differently if the workflow fails vs succeeds"

    and

    "to be able to show (in a notification, for example) when a record has a background process running on it"

    we should see "success" status in regards to some record. Without unchecking the option, if workflow fails once for some record, you'll never see successes for that record (after succeeded instances cleanups).

  • Dipei Profile Picture
    Dipei on at
    RE: Any way to tell/show when a background process is running?

    Hi SergiiChvyr,

    You are definite right, but think about it, why we need the "succeeded" one?

    If I understand the requirements here correctly, we only need the "running" or "failed" one.

    The option "Automatically delete completed workflow jobs" of process should be checked always except there are some particular reasons to uncheck it.

    Thanks,

    Dipei

  • SergiiChvyr Profile Picture
    SergiiChvyr on at
    RE: Any way to tell/show when a background process is running?

    At least you'll have to uncheck "Automatically delete completed workflow jobs"

  • SergiiChvyr Profile Picture
    SergiiChvyr on at
    RE: Any way to tell/show when a background process is running?

    This could give wrong results as successful workflow instances can be deleted automatically. This way, last success could be  deleted, while failed left. This will show failed, instead of correct result

  • Dipei Profile Picture
    Dipei on at
    RE: Any way to tell/show when a background process is running?

    Hi Allison,

    In your js codes, you can try the WEB API to get the backend system jobs statuscode which will show you the running status.

    Here is a sample for v8.2:

    https://{orgnization}.crm.dynamics.com/api/data/v8.2/asyncoperations?$select=statuscode,errorcode,message&$filter=primaryentitytype eq '{your entity logical name}' and _regardingobjectid_value eq {your entity id}

    Here are the potential status codes:

    Value: 0, Label: Waiting For Resources

    Value: 10, Label: Waiting

    Value: 20, Label: In Progress

    Value: 21, Label: Pausing

    Value: 22, Label: Canceling

    Value: 30, Label: Succeeded

    Value: 31, Label: Failed

    Value: 32, Label: Canceled

    It may returns the all system jobs (multiple records) which are related to the specified the entity record, if this is the case, you should try some other filters to get the one you want.

    Thanks,

    Dipei

  • SergiiChvyr Profile Picture
    SergiiChvyr on at
    RE: Any way to tell/show when a background process is running?

    Solution can be very different, depending on real requirements. As an easy option, you can create option set with several options like not started, processing, finished, failed. Let's say default is not started. When workflow starts, it sets to processing.After that you can start child workflow, which waits for couple of minutes and sets failed if status is still "processing". Parallel wait checks if status changed to "success" end finishes this child workflow if so. After calling this background child workflow may do its task and set to success in the end. Thus, if workflow successfully finished it sets success and child workflow exits as well, otherwise it fails and child workflow will do a cleanup with setting failed status.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans