none
CRM 2011 plugin to set initiating user id and current date to a custom modified by and modified on field

    Question

  • Hi All,

    I am a newbie to plugin development for CRM 2011 and I am looking to update custom modified by and modified on field on the Account form during a field change event.

    Case: When the Sales Stage field (custom field on the Account form) is changed by a user then the modifiedby and modified on field corresponding to this field should change to the following:

    ModifiedBy: Initiating User

    ModifiedOn: Current Date

    Here is a screenshot of the form:

    

    I have no idea how to proceed with this so any help will be greatly appreciated..

    Thanks!!

    Monday, March 25, 2013 11:55 AM

Answers

  • I have no idea why someone would suggest to use javascript here! So sad.

    Use a plugin for this. 

    Just set the 2 fields in a plugin triggered on create (pre-operation). 

    In the ‘update plugin’ check the inputparameters and use a preimage. If the salestage is submitted by the user, app, sync whatever (the value is in the inputparameters) and the value is changed (in comparison of the preimage) then set the 2 fields. (Also in a pre-operation plugin)
    Register this plugin to only run when the salestage is changed.

    If you do use javascript then your business logic is not applied when the user uses bulk edit for example. What do you tell you customer then? Hey you cannot use build in CRM features?

    Other examples:
    - Integrations with other systems (like Scribe)
    - (Re-)import using excel
    - Workflows
    - Third party apps (like mobile apps)
    - …

    Let me know if you need help with the plugin.

    • Marked as answer by Kushoon Monday, March 25, 2013 2:38 PM
    Monday, March 25, 2013 2:15 PM

All replies

  • its better to go for the javascript

    create an a javascript and fire the script on change

    function test()

    {

    var currentDateTime = new Date();

    Xrm.Page.getAttribute('modifiedon').setValue(currentDateTime);

    for user inofrmation check this link

    http://mahenderpal.wordpress.com/2011/05/11/get-current-user-id-and-name-in-javascript-ms-crm-2011/--by using link you can get user name and id

    }


    ms crm

    Monday, March 25, 2013 12:13 PM
  • I would have gone for  JS script (as I am fluent in JS and python) but the issue here is that we have a data load tool, 'Scribe', and if there is a plugin then the plugin will fire automatically every time the Scribe script to update the account is run, which won't happen if there was a JS script.
    Monday, March 25, 2013 12:34 PM
  • you cannot fire the plug-in on change,go for javascript is the correct process.


    ms crm

    Monday, March 25, 2013 12:43 PM
  • I have no idea why someone would suggest to use javascript here! So sad.

    Use a plugin for this. 

    Just set the 2 fields in a plugin triggered on create (pre-operation). 

    In the ‘update plugin’ check the inputparameters and use a preimage. If the salestage is submitted by the user, app, sync whatever (the value is in the inputparameters) and the value is changed (in comparison of the preimage) then set the 2 fields. (Also in a pre-operation plugin)
    Register this plugin to only run when the salestage is changed.

    If you do use javascript then your business logic is not applied when the user uses bulk edit for example. What do you tell you customer then? Hey you cannot use build in CRM features?

    Other examples:
    - Integrations with other systems (like Scribe)
    - (Re-)import using excel
    - Workflows
    - Third party apps (like mobile apps)
    - …

    Let me know if you need help with the plugin.

    • Marked as answer by Kushoon Monday, March 25, 2013 2:38 PM
    Monday, March 25, 2013 2:15 PM
  • Why don't you just enable the auditing? 

    Make sure auditing is checked in your fields, the entity and the organisation.

    No customization is needed...

    Tuesday, September 10, 2013 5:52 PM