Environment, company, branch and module handling
Defines ownership of Protheus environment setup and closure.
Overview
RpcSetEnv can choose company, branch, user, credential, module and tables for automatic routines that must own their context. Check its logical return. Menus, prepared Schedule and PrepareIn services may already own an environment: do not reinitialize or close it with RpcClearEnv. Documentation records an exception for prepared REST/SOAP contexts from 12.1.2510. From LIB 20251117 the credential argument accepts the specific token generated by totvs.framework.users.rpc.getAuthToken(); arbitrary tokens are not implied. The block only prepares opening, not a complete lifecycle. (Sources: refs. 1–1.)
Commented example
#Include "Protheus.ch"
User Function Ed695()
// Credential comes from an authorized caller; never log it.
// Uninvoked block: does not switch the current environment.
Local bOpen := {|cCompany,cTargetBranch,cUser,cCredential,cModule| ;
RpcSetEnv(cCompany,cTargetBranch,cUser,cCredential,cModule)}
ConOut(ValType(bOpen))
Return NilCreates block B without authenticating, opening or closing an environment. Real integration must check .T. and clean up only owned context. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Do not confuse work-area restoration with company switching. Keep credentials out of source/logs; verify rights, module and context ownership.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.