Often we need to pass user id and intercompany id to sql stored procedure to do some data selection from custom tables or to maintain the log regarding user activity. This happens with us with one custom window of Dynamics GP, in the beginning our stored procedure didn’t need user id and intercompany id parameters and was working fine but with the client requirement changes at some point we needed to pass these two parameters, adding parameters means creating chunk and deployment to all machines, which was not possible as users were connected and updated was necessary as it was hindering there routine work.
We can get intercompany id easily by using select dB_name() but we also needed to find the Dynamics GP user who is calling the stored procedure. To find that user we use this function inside our stored procedure and in this way avoid updating chunk.
This will returned the login dynamics gp user id when stored procedure will be called from GP.