web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(1) ShareShare
ReportReport
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

I have the same question (0)
  • SergiiChvyr Profile Picture
    on at
    RE: Any way to tell/show when a background process is running?

    Create an attribute, to which you may write a flag when workflow starts and reset it when it finishes. Inside your age is. Periodically check the value of that attribute

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

    Is there any way to set it differently if the workflow fails vs succeeds?  I'd need to know that, in addition to just the fact that it finished.

  • SergiiChvyr Profile Picture
    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.

  • Dipei Profile Picture
    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
    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

  • SergiiChvyr Profile Picture
    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"

  • Dipei Profile Picture
    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
    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).

  • awalters Profile Picture
    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...

  • Verified answer
    SergiiChvyr Profile Picture
    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans