I'm having an issue using the RuleExecutionContext on a Rule Event with custom Tokens. Essentially, I created a rule for when a user Posts (either reply or new thread). I also created some custom tokens to display for the "When" condition. I only want my tokens to show, but when I set it up, I lose access to the User context on the Action portion of the rule. How can I only show my tokens but still be able to select the triggering user on the Event part of the rule? I've tried a few different ways, but the documentation isn't quite clear. I've tried adding the Get<users> API to my Contextual Data Type ID as well as the Get<Users> API Content Type ID but neither seem to work unless I also add the ContentTypeId for Get<Users> to the ContectualDataTypeIds Enumerable. But if I do that, then it exposes all tokens associated with that ContentTypeId to the Conditional portion of the rules.
// Code from the rule Event public IEnumerable<Guid> ContextualDataTypeIds { get { return new[] { /*Apis.Get<Users>().ContentTypeId, Apis.Get<IForumThreads>().ContentTypeId,*/ Guid.Parse("760f7569-ddde-4ac6-8aeb-722e47eb7d83") // My custom DataTypeId from PostRuleTokens }; } } public RuleTriggerExecutionContext GetExecutionContext(RuleTriggerData data) { var context = new RuleTriggerExecutionContext(); var contentId = Guid.Parse(data["UserContentId"]); var threadId = int.Parse(data["ThreadId"]); context.Add(Apis.Get<Users>().ContentTypeId, Apis.Get<Users>().Get(new UsersGetOptions() { ContentId = contentId })); context.Add(Apis.Get<IForumThreads>().ContentTypeId, Apis.Get<IForumThreads>().Get(threadId)); return context; }
// Custom Tokens public void RegisterTokens(ITokenizedTemplateTokenController tokenController) { var dataTypeId = new Guid("760f7569-ddde-4ac6-8aeb-722e47eb7d83"); tokenController.Register(new TokenizedTemplateToken( "PostCount", "PostCountDescription", _controller, Guid.Parse("e558704b-b336-4174-a149-877d8f182c14"), dataTypeId, PrimitiveType.Int, context => memberService.GetMemberThreadAndReplyPostsCount(context.Get<User>(dataTypeId).Id ?? 0) )); tokenController.Register(new TokenizedTemplateToken( "PostDate", "PostDateDescription", _controller, Guid.Parse("fdc87d45-4856-4fb5-bdb0-bdcd74b25e7f"), dataTypeId, PrimitiveType.DateTime, context => Convert.ToDateTime("2018-01-01 00:00:00.000") //Test data )); }