Forum Discussion
Set portion of variable to two seperate variables
Hi guys,
I was asking to manipulate a session variable in APM There is a variable with full name (something like John Cooper) Take the last name and set it to session.ad.last.attr.firstname Take the first name and set it to session.ad.last.attr.lastname
So in the bottom line I need to set everything until the first "space" to variable and the rest of it to another variable.
So I have come up with an irule like this:
when ACCESS_POLICY_AGENT_EVENT { if {[ACCESS::policy agent_id] eq "aid_irule_EXTRACT-FIRST-LAST-NAME"} { set attribute [ACCESS::session data get session.ad.last.attr.displayname] set last_name [string range [findstr $attribute " "] end] set length_for_first_name [string length $sn]-[string length $attribute] set first_name [string range $attribute [length_for_first_name]] ACCESS::session data set session.ad.last.attr.firstname $first_name ACCESS::session data set session.ad.last.attr.lastname $last_name } }
I am not so familiar with the syntax of irules so any help for making this more simple would be very helpful for me
- Kevin_Stewart
Employee
As long as you're sure there's always only one space in the string, you could use a simple split to turn the values into a list:
when ACCESS_POLICY_AGENT_EVENT { if {[ACCESS::policy agent_id] eq "aid_irule_EXTRACT-FIRST-LAST-NAME" } { set name [split [ACCESS::session data get session.ad.last.attr.displayname] " "] ACCESS::session data set session.ad.last.attr.firstname [lindex ${name} 0] ACCESS::session data set session.ad.last.attr.lastname [lindex ${name} 1] } }
- Stanislas_Piro2
Cumulonimbus
In tcl, string with space is like a list with space as separator. No need to use split command.
In a variable assign, you can try this
session.ad.last.attr.firstname
lindex [ mcget {session.ad.last.attr.displayname}] 0
session.ad.last.attr.lastname
lrange [ mcget {session.ad.last.attr.displayname}] 1 end
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com