CRM 2013 - Plugin to retrieve username -
i have autonumber plug-in invokes when user presses save, i've received requirement append initials of person creating record end of ticket.
for example: 0001-0327-rbs
i have been able guid of user creating record, have no idea how literal value outside of sql. haven't been able figure out how can user name of active user creating record. possible within plug-in?
any appreciated. thanks.
you should iorganizationservice iserviceprovider
var context = (ipluginexecutioncontext)serviceprovider.getservice(typeof(ipluginexecutioncontext)); var servicefactory = (iorganizationservicefactory)serviceprovider.getservice(typeof(iorganizationservicefactory)); var service = servicefactory.createorganizationservice(context.userid);
now can retrieve systemuser using service:
var systemuser = service.retrieve("systemuser", context.userid, new microsoft.xrm.sdk.query.columnset(true));
in columnset can specify columns want retrieve (so example "firstname", "lastname", "fullname" etc.).
now can
systemuser["fullname"]
to name. or if using binds:
systemuser.toentity<systemuser>().fullname
Comments
Post a Comment