locked
OnSave bulk edit is not working RRS feed

  • Question

  • I have a custom entity on which I'd like to calculate the End Date/Time from Start Date/Time + Duration. I'm using the following JavaScript which woks fine:

     

    var start = crmForm.all.starDateTime.DataValue;  

    var duration = crmForm.all.duration.DataValue;  

    // Can't calculate without any data  

    if (start==undefined || start==null || duration==undefined || duration==null)  

    {  

        return;  

    }  

    var end = start;  

    end.setMinutes(end.getMinutes()+duration);  

    crmForm.all.EndDateTime.DataValue=end;

     

    However this doesn't work on data import or bulk edit! I came across few blogs which explains how to enable the bulk edit attribute in the customisation file. I have followed the procedure and change the line:

    <event name="onsave" application="false" active="true"> 

    to:

    <event name="onsave" application="false" active="true" BehaviorInBulkEditForm="Enabled">

    But still no luck when performing bulk edit! 

    Your help is very much appreciated. 

    Thanks

     

    Tuesday, March 29, 2011 4:27 PM

Answers

  • You can do date manipulation via Workflow via a custom workflow activity.  The CRM Manipulation Library on codeplex allows you to add/subtract days or business days from a given date attribute value and use the result to subsequently update an entity.  This assembly also provides string utilities, simple numeric calculations and regular expression search/replace.

    Unfortunately, it doesn't expose methods to add hours/minutes to a date, but I've written a custom workflow activity of my own that can do so.  I've just made the source code and binaries freely available, so you can use it in your own workflows.

    Once you've developed a workflow to add your Duration to your StartDateTime, make it available 'On Demand' and you can run it on a selection of entity instances as you were attempting to do via Bulk Edit.


    --pogo (pat)
    Wednesday, March 30, 2011 10:41 PM
  • Pogo, thanks for your instruction, but I couldn't get it to work.

    1. The plugin field does not get field in automatically! I tried entring this "(Workflow Activity) MrCRM.CRM.Workflow.AddTimeToDate.Workflow" manually but it return an error: "The Plugin was not specified. This a required field".
    2. Do I need to filter any attribute?
    3. Shouldn't this be a Create message? All the values are available when we create a record, so ideally we run this workflow when a record is created!

    Thanks

    vt

    Ok, here goes.  Hopefully the following pictorial representation will cover off (1) and (2) for you.  As for (3), that's entirely up to what you want to achieve.  If you need to create a new record, use a Create Record step; if you need to update a record, use an Update Record step.

    1. Step (1) uses the 'MrCRM:Add Time to Date' custom workflow activity adds 9 hrs to the Start Date of the Primary Entity, taking the time to 9:00am
    2. Step (2) uses the 'MrCRM:Add Time to Date' custom workflow activity adds 17 hrs to the Start Date of the Primary Entity, taking the time to 5:00pm
    3. Step (3) creates a new 'Service Activity' entity instance using the Output Properties from steps (1) and (2)

    Step 1

    1. 'Input Date' is populated by whichever DateTime field you wish to add time to
    2. 'Hours' is populated by the number of hours you wish to add - I've hard-coded it here, but you could also use a numeric entity attribute such as an 'int' or 'picklist'
    3. 'Minutes' is populated similarly to 'Hours'

    Step 2

    As per Step 1.

    Step 3

    In this step, we use the Output Properties generated from the previous custom workflow activity steps (you will only have one custom workflow activity step, as you are adding time to only one DateTime field).

    In the Create/Update Record step, via 'Set Properties', set the value of your result DateTime field using the Dynamic Values in the Form Assistant.  First, select the applicable custom workflow activity step (you will find it down the bottom of the 'Look for' drop-down under Local Values):

    Next, select the Output Property:

     


    --pogo (pat)
    Thursday, April 7, 2011 5:52 AM
  • Pogo, Thanks a lot. 

    That's brilliant! Very clever and clean way to do this.

    I tried to change the workflow name from "MrCRM" to something like "CustomWorkflow" so I modifyied the following in the .cs but didn't take effect on the CRM interface!

    I hope you don't mind if this get changed!

    Thanks

    vt

    namespace MrCRM.CRM.Workflow.AddTimeToDate
    {
    	[CrmWorkflowActivity("Add Time to Date", "CustomWorkflow")]
    	public class Workflow : SequenceActivity
    	{<span style="white-space:pre">		</span>
    

    • Marked as answer by vt123456 Thursday, April 14, 2011 10:59 AM
    Thursday, April 7, 2011 3:02 PM

All replies

  • Unfortunately, what you want to achieve is not possible via Bulk Edit, nor via Data Import.

    The javascript placed in a form's and/or an attribute's event handler only works because it is hosted in a browser (an application that can parse, compile and execute javascript).  When importing data via a Data Import, the Entity form is not even instantiated, so the javascript could never have had a chance to run.

    When using Bulk Edit, although you can enable events in Bulk Edit, they can only operate on what they see in the Bulk Edit form.  Your javascript is not iteratively run on every Entity instance you selected, but on the data available on the Bulk Edit form as entered by you.  This will work if you want to calculate fields to be exactly the same for each selected Entity instance, but not if you wish to perform calculations based on the data already stored within each Entity.

    Scripting is disabled by default for Bulk Editing for exactly these reasons.

    For such calculations, you will need to use either a plugin or custom workflow activity.  This will ensure that your business logic is adhered to, via any supported means of update.


    --pogo (pat)
    Tuesday, March 29, 2011 11:19 PM
  • if all users are using bulk edit i suggest move the logic to plugin which will be executed on record creation

     


    - Vijay
    Wednesday, March 30, 2011 8:04 AM
  • Thanks for your reply and its very unfortunate that we cant achieve that via bulk edit out of the box!

    Are you aware of similar sample code for either plugin or custom workflow activity?

    Kind regards,

    Wednesday, March 30, 2011 2:10 PM
  • You can do date manipulation via Workflow via a custom workflow activity.  The CRM Manipulation Library on codeplex allows you to add/subtract days or business days from a given date attribute value and use the result to subsequently update an entity.  This assembly also provides string utilities, simple numeric calculations and regular expression search/replace.

    Unfortunately, it doesn't expose methods to add hours/minutes to a date, but I've written a custom workflow activity of my own that can do so.  I've just made the source code and binaries freely available, so you can use it in your own workflows.

    Once you've developed a workflow to add your Duration to your StartDateTime, make it available 'On Demand' and you can run it on a selection of entity instances as you were attempting to do via Bulk Edit.


    --pogo (pat)
    Wednesday, March 30, 2011 10:41 PM
  • Thanks pogo69 :)

    I'm ganna have to upgrade my VS2005 to VS2008 before I can test your source code in my environment. 

    Thursday, March 31, 2011 12:03 PM
  • The compiled binaries are in the download if you wish to use them directly.
    --pogo (pat)
    Thursday, March 31, 2011 10:27 PM
  • Hi Pogo,

     

    I've register your plug-in and its available on workflow step in CRM.  I have three properties: Input Date, Hours, and Minutes, but I can't see the Output Date. 

    I would've thought the Output date be my EndDate and my workflow properies would be;  

    Output Date (EndDate) = Input Date (StartDate) + Minutes (duration)

     

    Also I tried to test it as it is so I put a date in (Input Date) and add 2 as value for Hours and made the workflow on Demand. Run the workflow but no joy!

    Do I need to modify your code?

    Thanks

    vt

    Tuesday, April 5, 2011 10:28 AM
  • Output Properties are available in subsequent steps via the Dynamic Value dialog.

    1. Create step using the Date Manipulation custom workflow activity - populate the Date and Hours/Minutes as required
    2. Create 'Update Record' step
    3. In Dynamic Value editor, select: 'Description you gave the step created in (1)' - this will be right down the bottom of the list of available entities/objects
    4. The Output Date property will now be available in the following drop-down

    I probably didn't explain that very well because I don't have a CRM installation in front of me right now.  Will try to update this when I get into work, but hopefully you'll follow me, as is.


    --pogo (pat)
    Tuesday, April 5, 2011 8:07 PM
  • Pogo, thanks for your instruction, but I couldn't get it to work.

    1. The plugin field does not get field in automatically! I tried entring this "(Workflow Activity) MrCRM.CRM.Workflow.AddTimeToDate.Workflow" manually but it return an error: "The Plugin was not specified. This a required field".
    2. Do I need to filter any attribute?
    3. Shouldn't this be a Create message? All the values are available when we create a record, so ideally we run this workflow when a record is created!

    Thanks

    vt

     

     

    Wednesday, April 6, 2011 10:41 AM
  • If I get time tomorrow, I'll take some screen snapshots.
    --pogo (pat)
    Wednesday, April 6, 2011 11:19 AM
  • Pogo, thanks for your instruction, but I couldn't get it to work.

    1. The plugin field does not get field in automatically! I tried entring this "(Workflow Activity) MrCRM.CRM.Workflow.AddTimeToDate.Workflow" manually but it return an error: "The Plugin was not specified. This a required field".
    2. Do I need to filter any attribute?
    3. Shouldn't this be a Create message? All the values are available when we create a record, so ideally we run this workflow when a record is created!

    Thanks

    vt

    Ok, here goes.  Hopefully the following pictorial representation will cover off (1) and (2) for you.  As for (3), that's entirely up to what you want to achieve.  If you need to create a new record, use a Create Record step; if you need to update a record, use an Update Record step.

    1. Step (1) uses the 'MrCRM:Add Time to Date' custom workflow activity adds 9 hrs to the Start Date of the Primary Entity, taking the time to 9:00am
    2. Step (2) uses the 'MrCRM:Add Time to Date' custom workflow activity adds 17 hrs to the Start Date of the Primary Entity, taking the time to 5:00pm
    3. Step (3) creates a new 'Service Activity' entity instance using the Output Properties from steps (1) and (2)

    Step 1

    1. 'Input Date' is populated by whichever DateTime field you wish to add time to
    2. 'Hours' is populated by the number of hours you wish to add - I've hard-coded it here, but you could also use a numeric entity attribute such as an 'int' or 'picklist'
    3. 'Minutes' is populated similarly to 'Hours'

    Step 2

    As per Step 1.

    Step 3

    In this step, we use the Output Properties generated from the previous custom workflow activity steps (you will only have one custom workflow activity step, as you are adding time to only one DateTime field).

    In the Create/Update Record step, via 'Set Properties', set the value of your result DateTime field using the Dynamic Values in the Form Assistant.  First, select the applicable custom workflow activity step (you will find it down the bottom of the 'Look for' drop-down under Local Values):

    Next, select the Output Property:

     


    --pogo (pat)
    Thursday, April 7, 2011 5:52 AM
  • Pogo, Thanks a lot. 

    That's brilliant! Very clever and clean way to do this.

    I tried to change the workflow name from "MrCRM" to something like "CustomWorkflow" so I modifyied the following in the .cs but didn't take effect on the CRM interface!

    I hope you don't mind if this get changed!

    Thanks

    vt

    namespace MrCRM.CRM.Workflow.AddTimeToDate
    {
    	[CrmWorkflowActivity("Add Time to Date", "CustomWorkflow")]
    	public class Workflow : SequenceActivity
    	{<span style="white-space:pre">		</span>
    

    • Marked as answer by vt123456 Thursday, April 14, 2011 10:59 AM
    Thursday, April 7, 2011 3:02 PM