Need an Idea for workflow to check if record exists, if not create a record, if yes - update record RRS feed

  • Question

  • I have a tricky question: I have several users that work on incidents, I would like to log the time each user spends on a form. For instance, here is the pseudo code:

    1. Check if Time Log for current user exists.
    2. If no Time Log exists - Create a new Time Log.
    3. If Time Log exists for current user - Update new time.

    This is what I would like:

    Name | Time
    Bryan 40 Minute
    Andrew 18 Minute
    Summit 1 Minute

    I created a new entity called Time Log, created the relevant fields and the time calculation scripts - however I am unsure how to implement the feature so that the same record is updated rather than a new record being created. What I have done so far is to create a new Workflow that adds the new time. But the record gets fired all the time and new records get created:

    Name | Time
    Bryan 40 Minutes
    Andrew 18 Minutes
    Summit 10  Minute
    Summit 30  Minute
    Bryan 19 Minutes
    Andrew 4   Minutes


    Does anyone know what I should be doing?

    • Edited by Sebd.DD Wednesday, November 27, 2013 10:08 AM
    Wednesday, November 27, 2013 10:06 AM

All replies

  • Hi Summit Shah,

    If i understand your problem correctly you need to register 2 workflow on demand. And in JavaScript check whether a record exists or not.
    If record already exists run first workflow (Update)
    Otherwise run second workflow (Create)

    Because you can not implement this logic using OOB
    1: Check if Time Log for current user exists.
    For you information
    Run workflow from JS

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    Linked-In Profile
    Follow me on Twitter!

    Wednesday, November 27, 2013 10:39 AM
  • Hello,

    You can implement your requirement through plugin, you can get modifiedby there to check if there is already some records exists for this user if not create new one.

    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, November 27, 2013 10:52 AM
  • This one is fairly easy if you know javascript. It works in Three parts:

    1. OnSave do a JS FetchXML query to see is a user with the GUID & The Record exists. If a Record DOES NOT exist - then:

    2. Create a new record using REST Create, or if it does exist, then:

    3. Update the Record by getting the record GUID

    I have done something similar myself. The XrmSvcToolkit is a lifesaver for these situations.

    Thursday, November 28, 2013 8:57 AM