cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Running a rule from an EmailTemplate

Running a rule from an EmailTemplate

Velocity Template Language (VTL) that we use to make the email notifications dynamic is very powerful, but it also takes a lot of effort and could sometimes take quite a bit of "trial and error" to get it all right. The syntax can be cumbersome and we do not always have the power that a programming language like Java or the BeanShell scripting language provides, especially if it comes to instantiating objects with parameters.

 

In a customer situation, I had to determine whether a work item was assigned directly to an identity (the owner), or that the original identity had a forward preference causing the work item to be assigned to the eventual owner.

 

To do so, I needed to instantiate the class sailpoint.api.Workflower and call the checkForward(...) method on that object. This turned out to be next to impossible. It is possible, however to get hold of an instance of the SailPointContext. Then using the SailPointContext, retrieve a Rule object and run that rule.

 

That means we can do even more magic! Rules can do just about anything! So, we can now more easily calculate things and return the outcome to a variable in the EmailTemplate.

 

So, how does this work? Well, first of all, we need to get hold of that SailPointContext. For that, see this blog post.

 

#set($spctx=$spTools.class.forName("sailpoint.api.SailPointFactory").getMethod("getFactory", null).invoke(null, null).getCurrentContext())

 

Then, we need to get the Rule object, for example "Example - My EmailTemplate Rule":

 

#set( $rule = $spctx.getObjectByName($spTools.class.forName("sailpoint.object.Rule"), "Example - My EmailTemplate Rule") )

 

Before we can run the rule, we need to set the rule argument as a List object. Let's assume that we just want the $identityName attribute to be provided as input to the rule. To add items to the list, we need to call the add() method on the List object. This however returns output, which would be printed in the template. To prevent that, we assign that output to a dummy variable.

 

#set( $ruleArgs=$spTools.class.forName("java.util.HashMap").newInstance() )
#set( $dummy = $ruleArgs.put( "identityName", $identityName ) )

 

Then we call the rule and assign the output of the rule to a new variable:

 

#set( $ruleOutput = $spctx.runRule($rule, $ruleArgs) )

 

The output of the rule can now be used in the template to make decisions, or to be part of the template.

 

Unfortunately, this trick will take a bit too many characters to do anything advanced in Subject, Cc and Bcc fields, but for the body, it's very useful.

Labels (1)
Comments

@ambujgera Yes, you can.

You can just instantiate the Util class and call methods on it:

#set($util=$spTools.class.forName("sailpoint.tools.Util").newInstance())
#set($list = $util.csvToList($csv))

 

Hi @rubajothi_c ,

The values generated in the body are not available in the subject. The trick described here probably won't work in the subject as the subject variable is just to short.

- Menno

Hi,

Thanks for this wonderful post. I was wondering if we need this rule to use a ManagedAttribute object inside an email template. Since we use the ManagedAttributer class to obtain the ManagedAttribute object, I am not sure if we can call that directly in an email template without the use of a rule.

Any ideas on that?

 

Thanks

Siddharth

You probably can, but the syntax is VTL is a bit more complex.

@menno_pieters 

Hi Menno,

in IIQ version 7.3p1 we used successful the call of a custom method getCC to fill custom value in cc of the initial notification emailtemplate for certification :

cc="$spTools.class.forName('sailpoint.services.task.EmailMethodLibrary').getMethod('getInstance',null).invoke(null,null).getCC($certification)"

But now we upgraded to IIQ version 8.1p3, and this is no longer working.

It show the code instead of the result returned by the method.

Do you have an idea why ? and a solution ?

 

Could you try getCc(...) instead of getCC(...)?

@menno_pieters 

Hi Menno,

my "getCC" was only mentioned as an example of a custom method within a custom class.

In reality its name is getCcListForMoverCertification. 

But now I heard the issue is due to the fact that since version 8.1p3 there is a fix included:
IIQMAG-3560    [SECURITY] IdentityIQ now restricts class loading from within Velocity templates except for email bodies

So this explains why suddenly the call in cc= (which is outside the template body) , is no longer working.

Hi @menno_pieters 

sailpoint is new thing for me, can you please let me know how i can fetch the value which is set here [ #set( $dummy = $ruleArgs.put( "identityName", $identityName ) ) }  in this rule ("Example - My EmailTemplate Rule")?

Currently I can run this rule through email template but not able to fetch the data in the rule.

Many Thanks

 

Hi @aloke_jana4 

The cool thing here is that the input argument "identityName" will be an actual variable in the BeanShell rule. That means that you can just use it. In many case, you may want to check for its existence, though:

if (identityName != void && identityName != null) {
  // do something with the identityName variable
}

 - Menno

Version history
Revision #:
3 of 3
Last update:
‎Mar 24, 2023 07:44 PM
Updated by: