locked
CRM 2011 - JScript permissions RRS feed

  • Question

  • I wonder if there is a way of executing some JScript code that reads or writes records using permissions not owned by the current user.

    For example, I made a JS function that cancels other user's activity under certain conditions, and it doesn't work unless the current user has the permission for writing activities other than his own. But I don't want to grant this pemission. I was thinking of something like SQL Server's Execute As. Can I do something like that?

    Thanks in advance!

    Wednesday, December 5, 2012 3:30 PM

Answers

  • Hi,
    As far as I know there is no possibility to execute JScript-statements against the crm server with other permissions as the ones of the current user.

    To solve your problem you can use a plugin and run this plugin as another user who has more permissions.

    Best regards,
    Andreas

    Andreas Buchinger
    Microsoft Dynamics Certified Technology Specialist
    MCPD: SharePoint Developer 2010

    Wednesday, December 5, 2012 5:06 PM
  • Integrated authentication will prevent you from doing this client side.  You need to create a proxy IOrganizationService under a different User Id.  The following code can be used in a Plug-in or custom workflow activity to generate an IOrganizationService under the System Admin user.  You will use the IOrganizationService generated to execute your transaction:

            public IOrganizationService GetSystemAdminProxy()
            {
                Organization org = _svc.Retrieve(Organization.EntityLogicalName, _context.OrganizationId, new ColumnSet("systemuserid")).ToEntity<Organization>();
                IOrganizationService svcProxy = (IOrganizationService)_factory.CreateOrganizationService((Guid)org.SystemUserId);
                return svcProxy;
            }
    

    -JayB

    Wednesday, December 5, 2012 5:18 PM

All replies

  • Hi,
    As far as I know there is no possibility to execute JScript-statements against the crm server with other permissions as the ones of the current user.

    To solve your problem you can use a plugin and run this plugin as another user who has more permissions.

    Best regards,
    Andreas

    Andreas Buchinger
    Microsoft Dynamics Certified Technology Specialist
    MCPD: SharePoint Developer 2010

    Wednesday, December 5, 2012 5:06 PM
  • Integrated authentication will prevent you from doing this client side.  You need to create a proxy IOrganizationService under a different User Id.  The following code can be used in a Plug-in or custom workflow activity to generate an IOrganizationService under the System Admin user.  You will use the IOrganizationService generated to execute your transaction:

            public IOrganizationService GetSystemAdminProxy()
            {
                Organization org = _svc.Retrieve(Organization.EntityLogicalName, _context.OrganizationId, new ColumnSet("systemuserid")).ToEntity<Organization>();
                IOrganizationService svcProxy = (IOrganizationService)_factory.CreateOrganizationService((Guid)org.SystemUserId);
                return svcProxy;
            }
    

    -JayB

    Wednesday, December 5, 2012 5:18 PM