Can I use a reference attribute in static transform attribute?

I have a transform that references 2 other transforms to get values. The problem is that when I try and use reference attribute, it doesn’t work. Here’s the static transform:

{
	"name": "Life Cycle State",
	"type": "static",
	"attributes": {
		"wdstatus": {
			"attributes": {
				"id": "Workday Lifecycle State based on Date"
			},
			"type": "reference"
		},
		"lhstatus": {
			"attributes": {
				"id": "LegalHoldValue"
			},
			"type": "reference"
		},
		"value": "#if($wdstatus==‘active’) active #elseif($lhstatus) inactive_legalhold #else inactive #end"
	}
}

I have a firstValid transform that is successfully using the 2 references. But I need to do some additional logic that I was hoping to do with an if/else logic. I broke it down to just use a single reference, and it still breaks.

{
	"name": "Life Cycle State",
	"type": "static",
	"attributes": {
		"wdstatus": {
			"attributes": {
				"id": "Workday Lifecycle State based on Date"
			},
			"type": "reference"
		},
		"value": "#if($wdstatus==‘active’) active #{else} inactive #end"
	}
}

The error is:
The application script threw an exception: com.sailpoint.seaspray.template.TemplateException: Error rendering template: #if($wdstatus==‘active’) active #{else} inactive #end BSF info: Cloud Promote Identity Attribute at line: 0 column: columnNo.

I did do a test which was successful with an identityAttribute and it had the logic:
“value”: “#if($variable2==‘Test’) true #{else} false #end
so I’m pretty sure it isn’t the #if/else syntax.

Any thoughts would be great. Are there limitations on reference transforms?

Hi @chrisp

Your single quote look wrong to me… Try this (also removing spacing)

#if($wdstatus == 'active')active#{else}inactive#end

Hey @chrisp,

Did this help to resolve your issue?

@Piyush Thanks for your response. Your code worked, but when I tried to use $lhstatus, as opposed to $wdstatus, I received an error:
Error rendering template: #if($lhstatus == ‘active’)active#{else}inactive#end

The only change was the variable name.

Thanks,
Chris

This paste of yours also seems to have the wrong single quote? Could you check that again?

@Piyush It wasn’t that, but it had to do with most users not having a $lhstatus value.
When I changed it to “#if($lhstatus)active#{else}inactive#end” I still get an error: Error rendering template: #if($lhstatus)active#{else}inactive#end

The user’s who do have a $lhstatus value returned as active, the other ones had an error. Is there some other way to check if the value isn’t there?

My ultimate goal is to evaluate both variables using this:
#if($wdstatus == 'active')active#{elseif}($lhstatus)inactive_legalhold#{else}inactive#end

Hey Chris, I did not see the reference transforms in comments but the problem looks like more of null values. The issue only occurs when you have value not populated under the variable. We use firstValid for these kind of problems and make sure at least a static value is populated in variable so even if we do not get from end source or other transform we have some kind of value which do not throw error in comparison.
You need to put static value and then do comparison in if condition to make sure you are not getting that value which is equal to non null comparison.

You want to do a first valid and pass a static as @chirag.patel has said… example

{
    "attributes": {
        "customAttr1": {
            "attributes": {
                "values": [
                    {
                        "attributes": {
                            "attributeName": "Attr1",
                            "sourceName": "Source1"
                        },
                        "type": "accountAttribute"
                    },
                    "NONE"
                ]
            },
            "type": "firstValid"
        },
        "customAttr2": {
            "attributes": {
                "values": [
                    {
                        "attributes": {
                            "attributeName": "Attr2",
                            "sourceName": "Source2"
                        },
                        "type": "accountAttribute"
                    },
                    "NONE"
                ]
            },
            "type": "firstValid"
        },
        "value": "#if($customAttr1 == 'Active')ActiveUser#elseif($customAttr2 != 'NONE')$customAttr2#else#end"
    },
    "id": "Example Transform",
    "type": "static"
}
1 Like

ok, so we can’t just use the ($lhstatus) to check if there is a value, but need to do a firstvalid check and return NONE if not there.
I’ll then need to do a check ($lhstatus == ‘NONE’). The full expression would be:
#if($wdstatus == 'active')active#{elseif}($lhstatus == 'NONE')inactive#{else}inactive_legalhold#end

Here is the complete Transform, for anyone’s reference:

{
	"name": "Life Cycle State",
	"type": "static",
	"attributes": {
		"wdstatus": {
			"attributes": {
				"id": "Workday Lifecycle State based on Date"
			},
			"type": "reference"
		},
		"lhstatus": {
			 "attributes": {
          "values": [
              {
							"attributes": {
								"id": "LegalHoldValue"
							},
							"type": "reference"
              },
              "NONE"
          ]
      },
      "type": "firstValid"
		},
		"value": "#if($wdstatus == 'active')active#{elseif}($lhstatus == 'NONE')inactive#{else}inactive_legalhold#end"
	}
}

@Piyush @chirag.patel Thank you for your help!

1 Like