I have been trying to find a good way to make "signatures" work in CRM. Some way for a manager to fill in a field for approval and then automatically put in the name of the manager into a field to prove that it was done by that person. I had found a way through some disabling the field and only opening it for users with a specific security role, but that still relied on the honesty of the managers. Some clients don't always trust their managers 100% unfortunately.
I have since found a post that gave me exactly what I was looking for. JavaScript that reads in the logged in user and puts the name of the logged in user into a text field automatically. So, whenever a specific field gets updated the user who changed it will get his/her name printed out so that all can see that the field was changed/approved by that user. Couple that with some additional JavaScript field level security and you've got a pretty good signature system. (Note that the field level security is NOT supported by Microsoft).
The cool part about finding the logged on user though is that it is supported JavaScript and uses the RetrieveMultiple CRM call to pull back the information desired. I take absolutely no credit for this code. I didn't have to really even change anything other than the output of the name so that it went into a field instead of an alert window. All credit goes to Michael Höhne, Microsoft Dynamics CRM MVP at Stunware. Here is the link to his post:
http://www.stunnware.com/crm2/topic.aspx?id=JSWebService
I have since found a post that gave me exactly what I was looking for. JavaScript that reads in the logged in user and puts the name of the logged in user into a text field automatically. So, whenever a specific field gets updated the user who changed it will get his/her name printed out so that all can see that the field was changed/approved by that user. Couple that with some additional JavaScript field level security and you've got a pretty good signature system. (Note that the field level security is NOT supported by Microsoft).
The cool part about finding the logged on user though is that it is supported JavaScript and uses the RetrieveMultiple CRM call to pull back the information desired. I take absolutely no credit for this code. I didn't have to really even change anything other than the output of the name so that it went into a field instead of an alert window. All credit goes to Michael Höhne, Microsoft Dynamics CRM MVP at Stunware. Here is the link to his post:
http://www.stunnware.com/crm2/topic.aspx?id=JSWebService
The code from his post is this:
var xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
" <soap:Body>" +
" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\" xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" +
" <q1:EntityName>systemuser</q1:EntityName>" +
" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
" <q1:Attributes>" +
" <q1:Attribute>systemuserid</q1:Attribute>" +
" <q1:Attribute>fullname</q1:Attribute>" +
" </q1:Attributes>" +
" </q1:ColumnSet>" +
" <q1:Distinct>false</q1:Distinct>" +
" <q1:Criteria>" +
" <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>systemuserid</q1:AttributeName>" +
" <q1:Operator>EqualUserId</q1:Operator>" +
" </q1:Condition>" +
" </q1:Conditions>" +
" </q1:Criteria>" +
" </query>" +
" </soap:Body>" +
"</soap:Envelope>" + "";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2006/CrmService.asmx", false);
xmlHttpRequest.Open("POST", "/mscrmservices/2006/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length); xmlHttpRequest.send(xml);
var doc = xmlHttpRequest.responseXML; var user = doc.selectSingleNode("//BusinessEntity");
var doc = xmlHttpRequest.responseXML; var user = doc.selectSingleNode("//BusinessEntity");
var userId = user.selectSingleNode("systemuserid").text;
alert(userId);
var userName = user.selectSingleNode("fullname").text;
alert(userName);
You can quite literally copy and paste the code into any JavaScript function inside of CRM and this will work. There is nothing that ties it to one CRM implementation or another.
My hat goes off the Michael and the rest of the Stunware team for their great work and sharing this spectactular code. Thanks guys.
Happy coding,
David Fronk
Dynamic Methods Inc.