Macro rule passing in to many parameters

Zachary Perry asked on March 31, 2017 18:19

Using K9 I have a custom module that uses macro rules, and a custom scheduled task to evaluate the rules.

I have one rule, that is the same format as the others, that when I run my scheduled task, it passes in 5 parameters to the macro, instead of 4.

This is the macro rule condition: (_has)BadgeRule.HasLikedArticle(User,{count},"{start}", "{end}") User is handled in the scheduled task:

  MacroResolver resolver = MacroResolver.GetInstance();
  resolver.SetNamedSourceData("User", user);
  var result = ValidationHelper.GetBoolean(resolver.ResolveMacros(badge.BadgeRequirements), false);

When I debug the custom macro, it says 5 parameters are passed in, the first is null, and the other 4 are the ones I am passing in from the condition.

If I go to System > Macros > Benchmark and run this: {% BadgeRule.HasLikedArticle(GlobalObjects.Users.Where("UserID = 7563").FirstItem,1,DateTime.CurrentDateTime.AddDays(-1), DateTime.Now.AddDays(8)) #%}

it passes in 4 parameters as expected.

I use this similar format (user, other params) for multiple rules/custom macros, and have no issue, but for this one it seems to break and I can't figure out why.

Recent Answers

Trevor Fayas answered on April 1, 2017 16:02

My guess is because if you call a function from an object, that object is passed as the first parameter (exaple SomeStringVariable.Replace("a","b") has 3 parameters, SomeSTringVariable, A and B)

In most macro examples, it does a SWITCH on the parameters length, so you can detect if there are 4 or 5. You may need to do additional logic to account for if it's getting a null as it's first one.

To verify, in the case where null is passed as the first, see if the other variables just shifted down a spot.

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on April 1, 2017 17:30

I found the issue, I was using (_has) in the macro condition instead of {_has}

2 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.