Agregar usuario a Site de Sharepoint
Escrito por René Roca el . Posteado en X++En Dynamics Ax 4.0, podíamos agregar un usuario de Axapta a un grupo de usuario de Sharepoint desde el Menu Principal -> Administración -> Usuarios -> Boton Usuarios relacionados -> Pestaña WebSite.
Desgraciadamente, esta opción ha sido eliminada en Dynamics Ax 2009. Nosotros podemos volver a tener esta opción mediante un Job de X++
El siguiente ejemplo, agrega un usuario de Axapta al grupo de propietarios de Sharepoint mediante CLRInterop, para ello primero de todo tendremos que agrear la DDL Microsoft.Sharepoint.dll a nuestro AOT
static void AddAXUserToSharepointGroup(Args _args) { Microsoft.SharePoint.SPWeb spWeb; Microsoft.SharePoint.SPSite spSite; Microsoft.SharePoint.SPGroupCollection spGroupCollection; Microsoft.SharePoint.SPGroup spGroup; Microsoft.SharePoint.SPUserCollection spUserCollection; Microsoft.SharePoint.SPUser spUser; EPWebSiteParameters epWebSiteParameters; UserInfo userInfo; SysUserInfo sysUserInfo; str loginName; System.Exception ex; str siteGroupName; ; try { //Sharepoint registrado en AX2009 select firstonly epWebSiteParameters; select firstonly userInfo where userInfo.id == curUserId(); select firstonly sysUserInfo where sysUserInfo.Id == curUserId(); loginName = userInfo.networkDomain + '\\' + userInfo.networkAlias; spSite = new Microsoft.SharePoint.SPSite(epWebSiteParameters.InternalUrl); spWeb = spSite.get_RootWeb(); //Crea el usuario en Sharepoint spUserCollection = spWeb.get_SiteUsers(); spUserCollection.Add(loginName, sysUserInfo.Email, userInfo.name, ""); //Agrega el usuario al grupo de propietarios spUser = spUserCollection.get_Item(loginName); spGroupCollection = spWeb.get_SiteGroups(); siteGroupName = CLRInterop::getAnyTypeForObject(spWeb.get_Title()) + " Owners"; //Or Visitors, Members spGroup = spGroupCollection.get_Item(siteGroupName); spGroup.AddUser(spUser); spGroup.Update(); } catch (exception::CLRError) { ex = CLRinterop::getLastException(); try { if (ex) { info(ex.ToString()); } } catch (exception::Internal) { ex = clrinterop::getLastException(); if (ex) { info(ex.ToString()); } } } }
Etiquetas:add, Dynamics Ax, owner, Sharepoint, user