How do I assign the current system user to a user defined user field on a custom entity RRS feed

  • Question


    I am trying to map the current user to a user defined user type field on a save event and I am having trouble determining what to do.  I am not sure if I am using the wrong system value or I need to approach this differently.  My sample code is listed below (just this one line).

    crmForm.all.ee_userfieldid.DataValue = User.systemuserid.Value;

    I have also tried this and it did not work

    crmForm.all.ee_userfieldid.DataValue = EntityName.systemuser.ToString();






    Scott Clancy
    Friday, March 4, 2011 11:47 PM

All replies


    This is on Dynamics 4.0 with update 14.

    The error I get when running this is "user' is undefined.

    My expectations are that the user defined field gets set to the person who is saving the record.  I can't use modified by or created by since those fields are NULL on new records.


    Scott Clancy
    Saturday, March 5, 2011 1:19 AM
  • You're attempting to mix Javascript code with C# code.

    From within an Entity form event, your javascript code has no inherent knowledge of the identity of the currently logged in User.  To obtain the current User GUID, you must perform a WhoAmI operation.  The code in the following URL provides an example of how:


    Scroll down to the CRM 4.0 section.  You need the SystemUserId and FullName variables that are declared.

    If your 'ee_userfieldid' field represents a Lookup attribute, you need code similar to the following to populate it:

    var lookup = new Array();
    var lookupItem = new Object();
    lookupItem.id = SystemUserId;
    lookupItem.typename = 'systemuser';
    lookupItem.name = FullName;
    lookup[0] = lookupItem;
    crmForm.all.ee_userfieldid.DataValue = lookup;



    --pogo (pat)
    Monday, March 7, 2011 1:23 AM