Skip to main content
February 2, 2021
Question

How to retrieve the calling User in a custom function without passing it as a parameter ?

  • February 2, 2021
  • 2 replies
  • 0 views

Hello, 

Could you please tell me how can i retrieve the caller of a custom function inside this function (in java) ?  I would like to check at least if he has the sysadmin rights.

Thanks in advance 

David 

2 replies

February 3, 2021

After exploring different plugins, it appears that the only context injectable in custom functions is  com.appiancorp.services.ServiceContext.

Since then, it's possible to retrieve the caller like shown in the next reply.

 

February 3, 2021


	@Function
	public TypedValue sysInfo(ServiceContext
			  sc,UserProfileService ups_) throws AppianException {
		HashMap ret = new HashMap();
		try {
			
			UserProfile profile = ups_.getUser(sc.getName());
			if (!profile.getUserTypeId().equals(UserProfile.USER_TYPE_SYS_ADMIN)) {
				String errorText = "User " + profile.getUsername()
						+ " is not a System Administrator.  You must run sysInfo as an administrator.";
				LOG.error(errorText);
				throw new Exception(errorText);
			}
			
	.....