Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
lvaradha Absent Member.
Absent Member.
171 views

Holding array of values inside the foreach loop


I have requirement, where when i grants JDBCGroup entitlement the below
rule will trigger and email the Group information in eMail. This works
fine when i grant one JDBCGroup entitlement.
If i grant multiple JDBCGroup entitlement same time.

For example granting 2 JDBCGroup entitlement, triggers two separate
emails for each JDBCGroup entitlement value.
email is send to user with JDBCGroup "entitlement value" as below

email:1
To:User1
Message: Group1

email:2
To:User1
Message:Group2

If i give send mail action outside the loop it send only the last
granted entitlement value.

Here is what i need:
Send email once with all the JDBCGroup entitlement value granted.

Example:

email:1
To:User1
Message:
Group1
Group2

Basically i need to hold (not overwrite) the group entitlement value
inside the loop, and use it outside the loop.

Below is my current policy

<rule>
<description>Implement JDBC Group Entitlement</description>
<conditions>
<and>
<if-class-name mode="nocase" op="equal">User</if-class-name>
<if-association op="associated"/>
<if-entitlement name="JDBCGroup" op="changing"/>
</and>
</conditions>
<actions>
<do-for-each>
<arg-node-set>
<token-added-entitlement name="JDBCGroup"/>
</arg-node-set>
<arg-actions>
<do-add-dest-attr-value class-name="User" name="CUSTJDBCGroup">
<arg-value type="string">
<token-added-entitlement name="JDBCGroup"/>
</arg-value>
</do-add-dest-attr-value>
<do-send-email-from-template notification-dn="Security\Default
Notification Collection" template-dn="Security\Default Notification
Collection\Havigs JDBC Groups provisioning notification">
<arg-string name="to">
<token-src-attr name="Internet EMail Address"/>
</arg-string>
<arg-string name="firstname">
<token-src-attr name="Given Name"/>
</arg-string>
<arg-string name="lastname">
<token-src-attr name="Surname"/>
</arg-string>
<arg-string name="loginID">
<token-src-attr name="CN"/>
</arg-string>
<arg-string name="bcc">
<token-text xml:space="preserve">abc@novell.com</token-text>
</arg-string>
<arg-string name="secgroup">
<token-added-entitlement name="JDBCGroup"/>
</arg-string>
</do-send-email-from-template>
</arg-actions>
</do-for-each>
</actions>
</rule>


--
lvaradha
------------------------------------------------------------------------
lvaradha's Profile: http://forums.novell.com/member.php?userid=77512
View this thread: http://forums.novell.com/showthread.php?t=454747

Labels (1)
0 Likes
2 Replies
Knowledge Partner
Knowledge Partner

Re: Holding array of values inside the foreach loop

On Tue, 17 Apr 2012 19:46:01 +0000, lvaradha wrote:

> I have requirement, where when i grants JDBCGroup entitlement the below
> rule will trigger and email the Group information in eMail. This works
> fine when i grant one JDBCGroup entitlement. If i grant multiple
> JDBCGroup entitlement same time.


There are no arrays, but there are nodesets.


> If i give send mail action outside the loop it send only the last
> granted entitlement value.
>
> Here is what i need:
> Send email once with all the JDBCGroup entitlement value granted.


Inside your for-each loop, append each current-value from the nodeset to
a string. Outside the loop, use the resulting string in your email
message body.


--
--------------------------------------------------------------------------
David Gersic dgersic_@_niu.edu
Knowledge Partner http://forums.novell.com

Please post questions in the forums. No support provided via email.

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: Holding array of values inside the foreach loop

On 6/1/2012 10:46 AM, lvaradha wrote:
>
> Hi it would be great if i get some example.
>
>

Here are some examples of various ways you can do this. These are intended just to show you some
ideas. They could be made a lot more efficient just depending on what you wanted to do.

<rule>
<description>maintain a variable through a loop</description>
<comment xml:space="preserve">this is a loop that builds a cumulative variable in both a string
and a nodeset</comment>
<conditions>
<and/>
</conditions>
<actions>
<do-set-local-variable name="cumulativeVarStr" scope="policy">
<arg-string/>
</do-set-local-variable>
<do-set-local-variable name="cumulativeVarNodes" scope="policy">
<arg-node-set>
<token-xml-parse>
<token-text xml:space="preserve"><table><tr /></table></token-text>
</token-xml-parse>
</arg-node-set>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-op-attr name="departmentNumber"/>
</arg-node-set>
<arg-actions>
<do-trace-message>
<arg-string>
<token-text xml:space="preserve">Here you do some actions</token-text>
</arg-string>
</do-trace-message>
<do-if>
<arg-conditions>
<and>
<if-local-variable mode="nocase" name="cumulativeVarStr" op="equal"/>
</and>
</arg-conditions>
<arg-actions>
<do-set-local-variable name="cumulativeVarStr" scope="policy">
<arg-string>
<token-local-variable name="current-node"/>
</arg-string>
</do-set-local-variable>
</arg-actions>
<arg-actions>
<do-set-local-variable name="cumulativeVarStr" scope="policy">
<arg-string>
<token-local-variable name="cumulativeVarStr"/>
<token-text xml:space="preserve">|</token-text>
<token-local-variable name="current-node"/>
</arg-string>
</do-set-local-variable>
</arg-actions>
</do-if>
<do-append-xml-element expression="$cumulativeVarNodes/table/tr" name="td"/>
<do-append-xml-text expression="$cumulativeVarNodes/table/tr/td[last()]">
<arg-string>
<token-local-variable name="current-node"/>
</arg-string>
</do-append-xml-text>
</arg-actions>
</do-for-each>
<do-trace-message>
<arg-string>
<token-text xml:space="preserve">String:</token-text>
<token-local-variable name="cumulativeVarStr"/>
<token-text xml:space="preserve">Nodeset:</token-text>
<token-xml-serialize>
<token-local-variable name="cumulativeVarNodes"/>
</token-xml-serialize>
</arg-string>
</do-trace-message>
</actions>
</rule>
<rule>
<description>now use the variables in an email</description>
<comment xml:space="preserve">this then reformats the varaibles into a variable that is pretty
that you can use in an email message</comment>
<conditions>
<and/>
</conditions>
<actions>
<do-set-local-variable name="headerRow" scope="policy">
<arg-string>
<token-text xml:space="preserve">#######################</token-text>
<token-char value="0x000D"/>
<token-text xml:space="preserve"># Department Numbers #</token-text>
<token-char value="0x000D"/>
<token-text xml:space="preserve">#######################</token-text>
<token-char value="0x000D"/>
</arg-string>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-split delimiter="\|">
<token-local-variable name="cumulativeVarStr"/>
</token-split>
</arg-node-set>
<arg-actions>
<do-set-local-variable name="cumulativeVarStrArray" scope="policy">
<arg-string>
<token-local-variable name="cumulativeVarStrArray"/>
<token-text xml:space="preserve">#</token-text>
<token-local-variable name="current-node"/>
<token-text xml:space="preserve"> #</token-text>
<token-char value="0x000D"/>
</arg-string>
</do-set-local-variable>
</arg-actions>
</do-for-each>
<do-set-local-variable name="toEmailStrVar" scope="policy">
<arg-string>
<token-local-variable name="headerRow"/>
<token-local-variable name="cumulativeVarStrArray"/>
<token-text xml:space="preserve">#######################</token-text>
</arg-string>
</do-set-local-variable>
<do-trace-message>
<arg-string>
<token-local-variable name="toEmailStrVar"/>
</arg-string>
</do-trace-message>
<do-trace-message>
<arg-string>
<token-xml-serialize>
<token-local-variable name="cumulativeVarNodes"/>
</token-xml-serialize>
</arg-string>
</do-trace-message>
</actions>
</rule>
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.