views:

174

answers:

1

I'm customizing a form in Microsoft's CRM Dynamics Online, and need to set a field value to the current users's ID. I've got code that correctly pulls the SystemUserID, but I'm having difficulty getting the value into the form field.

//Lots of XML/SOAP stuff to pull the user information
var systemUserIdNode = entityNode.selectSingleNode("q1:systemuserid");
crmForm.all.FieldForUserID.DataValue = systemUserIdNode; //Fails silently

[Update] After some digging, I've updated my code based on the sample in the SDK. It now looks like this:

var userIdValue = new Array();
userIdValue [0] = new LookupControlItem(systemUserIdNode, 8, fullNameNode);
crmForm.all.new_useridfield.DataValue = userIdValue ;

However, this causes an error in the last line - "Object doesn't support this property or method". So I'm still stumped (even more so, as the sample is out of the SDK).

+4  A: 

Try getting rid of your first two lines and replacing your third with

crmForm.all.new_useridfield.DataValue = 
    [{ 
        id: systemUserIdNode,
        name: fullNameNode,
        typename: 'systemuser'
    }];

The id property may require braces, so you might have to change it to:

id: '{' + systemUserIdNode + '}'
Polshgiant