<div dir="ltr">Can policy rules be used to put old value into a field? We still use the not recommended way, and moving away from that would make future upgrades easier and one less part that could break, example is below. For example, the reason we need old values populated and stored into a field is for username/email generation history as that value is also used in template to ensure it stays unique. We dont change usernames/emails often for people but every so often a higher up person will talk their way into making it happen.<div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">JASON</div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 15, 2022 at 8:08 AM Pavol Mederly via midPoint <<a href="mailto:midpoint@lists.evolveum.com">midpoint@lists.evolveum.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello Jean Michel,<br>
<br>
yes, policy rules have been created just for this kind of needs.<br>
<br>
Especially, there is a "transition" kind of policy constraint that fires <br>
if it sees a change from defined state S1 to another defined state S2: <br>
<a href="https://github.com/Evolveum/midpoint/blob/187bdb434b9b9524ce3a01849a137da7a2b261f0/infra/schema/src/main/resources/xml/ns/public/common/common-policy-3.xsd#L317-L332" rel="noreferrer" target="_blank">https://github.com/Evolveum/midpoint/blob/187bdb434b9b9524ce3a01849a137da7a2b261f0/infra/schema/src/main/resources/xml/ns/public/common/common-policy-3.xsd#L317-L332</a><br>
<br>
Some examples of its use are in this file: <br>
<a href="https://github.com/Evolveum/midpoint/blob/187bdb434b9b9524ce3a01849a137da7a2b261f0/model/model-impl/src/test/resources/lens/policy/role-student.xml" rel="noreferrer" target="_blank">https://github.com/Evolveum/midpoint/blob/187bdb434b9b9524ce3a01849a137da7a2b261f0/model/model-impl/src/test/resources/lens/policy/role-student.xml</a><br>
<br>
(But they are quite complex.)<br>
<br>
The file is used in this test: <br>
<a href="https://github.com/Evolveum/midpoint/blob/187bdb434b9b9524ce3a01849a137da7a2b261f0/model/model-impl/src/test/java/com/evolveum/midpoint/model/impl/lens/TestPolicyRules2.java" rel="noreferrer" target="_blank">https://github.com/Evolveum/midpoint/blob/187bdb434b9b9524ce3a01849a137da7a2b261f0/model/model-impl/src/test/java/com/evolveum/midpoint/model/impl/lens/TestPolicyRules2.java</a><br>
<br>
--<br>
<br>
This feature is quite an experimental one, with (as I said) very sketchy <br>
documentation. In short: it is there, should be functional, but to be <br>
100% polished it needs someone who would invest some money in it. <br>
Anyway, you can give it a try, maybe it would be OK for you.<br>
<br>
Best regards,<br>
<br>
-- <br>
Pavol Mederly<br>
Software developer<br>
<a href="http://evolveum.com" rel="noreferrer" target="_blank">evolveum.com</a><br>
<br>
On 15/08/2022 14:47, Jean Michel Santos via midPoint wrote:<br>
> Hello,<br>
><br>
> First of all, very sorry about the spam messages, my email client was not OK that day.<br>
><br>
> Imagine a scenario when you need to provide a new role, or notify the user manager, when the job code changes for a user. But not for all job codes, an specific one, like 001 to 003.<br>
><br>
> So, to compare I need to get the old value (001), and then compare with the new value(003) and if is true, take the  properly action to this rule.<br>
><br>
> Thanks in advance.<br>
><br>
> Regards,<br>
> Jean Santos<br>
><br>
> <a href="mailto:midpoint-request@lists.evolveum.com" target="_blank">midpoint-request@lists.evolveum.com</a> wrote:<br>
>> Send midPoint mailing list submissions to<br>
>>      <a href="mailto:midpoint@lists.evolveum.com" target="_blank">midpoint@lists.evolveum.com</a><br>
>><br>
>> To subscribe or unsubscribe via the World Wide Web, visit<br>
>>      <a href="https://lists.evolveum.com/mailman/listinfo/midpoint" rel="noreferrer" target="_blank">https://lists.evolveum.com/mailman/listinfo/midpoint</a><br>
>> or, via email, send a message with subject or body &#39;help&#39; to<br>
>>      <a href="mailto:midpoint-request@lists.evolveum.com" target="_blank">midpoint-request@lists.evolveum.com</a><br>
>><br>
>> You can reach the person managing the list at<br>
>>      <a href="mailto:midpoint-owner@lists.evolveum.com" target="_blank">midpoint-owner@lists.evolveum.com</a><br>
>><br>
>> When replying, please edit your Subject line so it is more specific<br>
>> than &quot;Re: Contents of midPoint digest...&quot;<br>
>><br>
>> Today&#39;s Topics:<br>
>><br>
>>    1. How to compare old with new value in Midpoint (Jean Santos)<br>
>>    2. How to compare old with new value in Midpoint (Jean Santos)<br>
>>    3. How to compare old with new value in Midpoint (Jean Michel Santos)<br>
>>    4. Re: How to compare old with new value in Midpoint (Pavol Mederly)<br>
>>    5. Re: How to compare old with new value in Midpoint (Pavol Mederly)<br>
>><br>
>> ----------------------------------------------------------------------<br>
>><br>
>> Message: 1<br>
>> Date: Fri, 12 Aug 2022 10:14:38 -0300<br>
>> From: Jean Santos &<a href="mailto:lt%3Bjean.michel@ebz.tec.br" target="_blank">lt;jean.michel@ebz.tec.br</a>&gt;<br>
>> To: &quot;=?utf-8?Q?midpoint=<a href="http://40lists.evolveum.com?=&quot" rel="noreferrer" target="_blank">40lists.evolveum.com?=&quot</a>;<br>
>>      &<a href="mailto:lt%3Bmidpoint@lists.evolveum.com" target="_blank">lt;midpoint@lists.evolveum.com</a>&gt;<br>
>> Subject: [midPoint] How to compare old with new value in Midpoint<br>
>> Message-ID: &<a href="mailto:lt%3BAF43F875-ECFA-4EC7-A0C9-CF2CD5315FA8@getmailspring.com" target="_blank">lt;AF43F875-ECFA-4EC7-A0C9-CF2CD5315FA8@getmailspring.com</a>&gt;<br>
>> Content-Type: text/plain; charset=&quot;utf-8&quot;<br>
>><br>
>> Hi Community,<br>
>><br>
>> In some cases, we need to compare the old and the new value(s) from an attribute to make a decision, I saw that when we&#39;re tracing in a mapping, we&#39;re able to see both values in the log. However, I don&#39;t know yet how to get those values inside a expression or condition and make a way to compare then.<br>
>> Could you please help me out in this question?<br>
>> Thanks in advance!<br>
>> Best Regards,<br>
>> Jean Michel Santos<br>
>> EbZ Tecnologia<br>
>> -------------- next part --------------<br>
>> An HTML attachment was scrubbed...<br>
>> URL: &lt;<a href="https://lists.evolveum.com/pipermail/midpoint/attachments/20220812/7f82e7bd/attachment-0002.htm&gt" rel="noreferrer" target="_blank">https://lists.evolveum.com/pipermail/midpoint/attachments/20220812/7f82e7bd/attachment-0002.htm&gt</a>;<br>
>><br>
>> ------------------------------<br>
>><br>
>> Message: 2<br>
>> Date: Fri, 12 Aug 2022 10:17:00 -0300<br>
>> From: Jean Santos &<a href="mailto:lt%3Bjean.michel@ebz.tec.br" target="_blank">lt;jean.michel@ebz.tec.br</a>&gt;<br>
>> To: &quot;=?utf-8?Q?midpoint=<a href="http://40lists.evolveum.com?=&quot" rel="noreferrer" target="_blank">40lists.evolveum.com?=&quot</a>;<br>
>>      &<a href="mailto:lt%3Bmidpoint@lists.evolveum.com" target="_blank">lt;midpoint@lists.evolveum.com</a>&gt;<br>
>> Subject: [midPoint] How to compare old with new value in Midpoint<br>
>> Message-ID: &<a href="mailto:lt%3BAF43F875-ECFA-4EC7-A0C9-CF2CD5315FA8@getmailspring.com" target="_blank">lt;AF43F875-ECFA-4EC7-A0C9-CF2CD5315FA8@getmailspring.com</a>&gt;<br>
>> Content-Type: text/plain; charset=&quot;utf-8&quot;<br>
>><br>
>> Hi Community,<br>
>><br>
>> In some cases, we need to compare the old and the new value(s) from an attribute to make a decision, I saw that when we&#39;re tracing in a mapping, we&#39;re able to see both values in the log. However, I don&#39;t know yet how to get those values inside a expression or condition and make a way to compare then.<br>
>> Could you please help me out in this question?<br>
>> Thanks in advance!<br>
>> Best Regards,<br>
>> Jean Michel Santos<br>
>> EbZ Tecnologia<br>
>> -------------- next part --------------<br>
>> An HTML attachment was scrubbed...<br>
>> URL: &lt;<a href="https://lists.evolveum.com/pipermail/midpoint/attachments/20220812/7f82e7bd/attachment-0003.htm&gt" rel="noreferrer" target="_blank">https://lists.evolveum.com/pipermail/midpoint/attachments/20220812/7f82e7bd/attachment-0003.htm&gt</a>;<br>
>><br>
>> ------------------------------<br>
>><br>
>> Message: 3<br>
>> Date: Fri, 12 Aug 2022 13:19:08 -0000<br>
>> From: &quot;Jean Michel Santos&quot; &<a href="mailto:lt%3Bjean.michel@ebz.tec.br" target="_blank">lt;jean.michel@ebz.tec.br</a>&gt;<br>
>> To: <a href="mailto:midpoint@lists.evolveum.com" target="_blank">midpoint@lists.evolveum.com</a><br>
>> Subject: [midPoint] How to compare old with new value in Midpoint<br>
>> Message-ID: &lt;166031034859.1526.2424895894819339684@mail.ebz&gt;<br>
>> Content-Type: text/plain; charset=&quot;utf-8&quot;<br>
>><br>
>> Hi Community,<br>
>><br>
>> In some cases, we need to compare the old and the new value(s) from an attribute to make a decision, I saw that when we&#39;re tracing in a mapping, we&#39;re able to see both values in the log. However, I don&#39;t know yet how to get those values inside a expression or condition and make a way to compare then.<br>
>><br>
>> Could you please help me out in this question?<br>
>><br>
>> Thanks in advance!<br>
>><br>
>> Best Regards,<br>
>><br>
>> Jean Michel Santos<br>
>> EbZ Tecnologia<br>
>><br>
>> ------------------------------<br>
>><br>
>> Message: 4<br>
>> Date: Sat, 13 Aug 2022 00:48:15 +0200<br>
>> From: Pavol Mederly &<a href="mailto:lt%3Bmederly@evolveum.com" target="_blank">lt;mederly@evolveum.com</a>&gt;<br>
>> To: <a href="mailto:midpoint@lists.evolveum.com" target="_blank">midpoint@lists.evolveum.com</a><br>
>> Subject: Re: [midPoint] How to compare old with new value in Midpoint<br>
>> Message-ID: &<a href="mailto:lt%3B1e5136ef-e566-9b58-1fa9-7ecdd4c17ff7@evolveum.com" target="_blank">lt;1e5136ef-e566-9b58-1fa9-7ecdd4c17ff7@evolveum.com</a>&gt;<br>
>> Content-Type: text/plain; charset=UTF-8; format=flowed<br>
>><br>
>> Hello Jean Michel,<br>
>><br>
>> midPoint transparently works with old and new values, as explained e.g.<br>
>> here:<br>
>> <a href="https://docs.evolveum.com/midpoint/reference/expressions/mappings/mapping-relativity/" rel="noreferrer" target="_blank">https://docs.evolveum.com/midpoint/reference/expressions/mappings/mapping-relativity/</a>.<br>
>><br>
>> Isn&#39;t that sufficient for you? What is the use case where you need to<br>
>> explicitly access (compare) old and new values?<br>
>><br>
>> --<br>
>><br>
>> Just for completeness, midPoint can process rules like &quot;If a user<br>
>> property changed from state S1 to state S2, execute action A&quot;. The<br>
>> states can be specified as concrete values, or using arbitrary expression.<br>
>><br>
>> This feature is called &quot;Policy rules&quot;. Although it works quite well, it<br>
>> is not documented enough (yet). See<br>
>> <a href="https://docs.evolveum.com/midpoint/reference/roles-policies/policy-rules/" rel="noreferrer" target="_blank">https://docs.evolveum.com/midpoint/reference/roles-policies/policy-rules/</a>.<br>
>><br>
>> --<br>
>><br>
>> Best regards,<br>
>><br>
>> -- <br>
>> Pavol Mederly<br>
>> Software developer<br>
>> <a href="http://evolveum.com" rel="noreferrer" target="_blank">evolveum.com</a><br>
>><br>
>> On 12/08/2022 15:19, Jean Michel Santos via midPoint wrote:<br>
>> &gt; Hi Community,<br>
>> &gt;<br>
>> &gt; In some cases, we need to compare the old and the new value(s) from an attribute to make a decision, I saw that when we&#39;re tracing in a mapping, we&#39;re able to see both values in the log. However, I don&#39;t know yet how to get those values inside a expression or condition and make a way to compare then.<br>
>> &gt;<br>
>> &gt; Could you please help me out in this question?<br>
>> &gt;<br>
>> &gt; Thanks in advance!<br>
>> &gt;<br>
>> &gt; Best Regards,<br>
>> &gt;<br>
>> &gt; Jean Michel Santos<br>
>> &gt; EbZ Tecnologia<br>
>> &gt; _______________________________________________<br>
>> &gt; midPoint mailing list<br>
>> &gt; <a href="mailto:midPoint@lists.evolveum.com" target="_blank">midPoint@lists.evolveum.com</a><br>
>> &gt; <a href="https://lists.evolveum.com/mailman/listinfo/midpoint" rel="noreferrer" target="_blank">https://lists.evolveum.com/mailman/listinfo/midpoint</a><br>
>><br>
>> ------------------------------<br>
>><br>
>> Message: 5<br>
>> Date: Sat, 13 Aug 2022 09:20:57 +0200<br>
>> From: Pavol Mederly &<a href="mailto:lt%3Bmederly@evolveum.com" target="_blank">lt;mederly@evolveum.com</a>&gt;<br>
>> To: <a href="mailto:midpoint@lists.evolveum.com" target="_blank">midpoint@lists.evolveum.com</a><br>
>> Subject: Re: [midPoint] How to compare old with new value in Midpoint<br>
>> Message-ID: &<a href="mailto:lt%3Bc72e28b9-9f9e-1b82-0a4d-b25f8ef44048@evolveum.com" target="_blank">lt;c72e28b9-9f9e-1b82-0a4d-b25f8ef44048@evolveum.com</a>&gt;<br>
>> Content-Type: text/plain; charset=&quot;utf-8&quot;; Format=&quot;flowed&quot;<br>
>><br>
>> Jean Michel,<br>
>><br>
>> there is a dirty hack that could be used as a last resort:<br>
>><br>
>> The properties *modelContext.focusContext.objectOld*, *.objectCurrent*,<br>
>> and *.objectNew* provide old, current, and new (expected) values of the<br>
>> focus object, respectively.<br>
>><br>
>> There you can find old/new values of the user property, and act upon them.<br>
>><br>
>> But it is strongly recommended to *NOT* do so. Among the reasons is that<br>
>> it creates the dependency of your design on the internal midPoint<br>
>> workings that can change anytime. Also, the use of these<br>
>> undocumented/internal mechanisms may provide unexpected results in some<br>
>> situations.<br>
>><br>
>> The best way forward is to exploit supported midPoint features and - if<br>
>> needed - discuss with us about their potential extension to cover your<br>
>> needs.<br>
>><br>
>> Best regards,<br>
>><br>
>> -- <br>
>> Pavol Mederly<br>
>> Software developer<br>
>> <a href="http://evolveum.com" rel="noreferrer" target="_blank">evolveum.com</a><br>
>><br>
>> On 13/08/2022 00:48, Pavol Mederly via midPoint wrote:<br>
>> &gt; Subject:<br>
>> &gt; Re: [midPoint] How to compare old with new value in Midpoint<br>
>> &gt; From:<br>
>> &gt; Pavol Mederly via midPoint &<a href="mailto:lt%3Bmidpoint@lists.evolveum.com" target="_blank">lt;midpoint@lists.evolveum.com</a>&gt;<br>
>> &gt; Date:<br>
>> &gt; 13/08/2022, 00:48<br>
>> &gt;<br>
>> &gt; To:<br>
>> &gt; <a href="mailto:midpoint@lists.evolveum.com" target="_blank">midpoint@lists.evolveum.com</a><br>
>> &gt; CC:<br>
>> &gt; Pavol Mederly &<a href="mailto:lt%3Bmederly@evolveum.com" target="_blank">lt;mederly@evolveum.com</a>&gt;<br>
>> &gt;<br>
>> &gt;<br>
>> &gt; Hello Jean Michel,<br>
>> &gt;<br>
>> &gt; midPoint transparently works with old and new values, as explained<br>
>> &gt; e.g. here:<br>
>> &gt; <a href="https://docs.evolveum.com/midpoint/reference/expressions/mappings/mapping-relativity/" rel="noreferrer" target="_blank">https://docs.evolveum.com/midpoint/reference/expressions/mappings/mapping-relativity/</a>.<br>
>> &gt;<br>
>> &gt;<br>
>> &gt; Isn&#39;t that sufficient for you? What is the use case where you need to<br>
>> &gt; explicitly access (compare) old and new values?<br>
>> &gt;<br>
>> &gt; --<br>
>> &gt;<br>
>> &gt; Just for completeness, midPoint can process rules like &quot;If a user<br>
>> &gt; property changed from state S1 to state S2, execute action A&quot;. The<br>
>> &gt; states can be specified as concrete values, or using arbitrary<br>
>> &gt; expression.<br>
>> &gt;<br>
>> &gt; This feature is called &quot;Policy rules&quot;. Although it works quite well,<br>
>> &gt; it is not documented enough (yet). See<br>
>> &gt; <a href="https://docs.evolveum.com/midpoint/reference/roles-policies/policy-rules/" rel="noreferrer" target="_blank">https://docs.evolveum.com/midpoint/reference/roles-policies/policy-rules/</a>.<br>
>> &gt;<br>
>> &gt;<br>
>> &gt; --<br>
>> &gt;<br>
>> &gt; Best regards,<br>
>> &gt;<br>
>> &gt; --<br>
>> &gt; Pavol Mederly<br>
>> &gt; Software developer<br>
>> &gt; <a href="http://evolveum.com" rel="noreferrer" target="_blank">evolveum.com</a><br>
>> &gt;<br>
>> &gt; On 12/08/2022 15:19, Jean Michel Santos via midPoint wrote:<br>
>> &gt;&gt; Hi Community,<br>
>> &gt;&gt;<br>
>> &gt;&gt; In some cases, we need to compare the old and the new value(s) from<br>
>> &gt;&gt; an attribute to make a decision, I saw that when we&#39;re tracing in a<br>
>> &gt;&gt; mapping, we&#39;re able to see both values in the log. However, I don&#39;t<br>
>> &gt;&gt; know yet how to get those values inside a expression or condition and<br>
>> &gt;&gt; make a way to compare then.<br>
>> &gt;&gt;<br>
>> &gt;&gt; Could you please help me out in this question?<br>
>> &gt;&gt;<br>
>> &gt;&gt; Thanks in advance!<br>
>> &gt;&gt;<br>
>> &gt;&gt; Best Regards,<br>
>> &gt;&gt;<br>
>> &gt;&gt; Jean Michel Santos<br>
>> &gt;&gt; EbZ Tecnologia<br>
>> &gt;&gt; _______________________________________________<br>
>> &gt;&gt; midPoint mailing list<br>
>> &gt;&gt; <a href="mailto:midPoint@lists.evolveum.com" target="_blank">midPoint@lists.evolveum.com</a><br>
>> &gt;&gt; <a href="https://lists.evolveum.com/mailman/listinfo/midpoint" rel="noreferrer" target="_blank">https://lists.evolveum.com/mailman/listinfo/midpoint</a><br>
>> &gt; _______________________________________________<br>
>> &gt; midPoint mailing list<br>
>> &gt; <a href="mailto:midPoint@lists.evolveum.com" target="_blank">midPoint@lists.evolveum.com</a><br>
>> &gt; <a href="https://lists.evolveum.com/mailman/listinfo/midpoint" rel="noreferrer" target="_blank">https://lists.evolveum.com/mailman/listinfo/midpoint</a><br>
>> -------------- next part --------------<br>
>> An HTML attachment was scrubbed...<br>
>> URL: &lt;<a href="https://lists.evolveum.com/pipermail/midpoint/attachments/20220813/d01583f1/attachment-0001.htm&gt" rel="noreferrer" target="_blank">https://lists.evolveum.com/pipermail/midpoint/attachments/20220813/d01583f1/attachment-0001.htm&gt</a>;<br>
>><br>
>> ------------------------------<br>
>><br>
>> Subject: Digest Footer<br>
>><br>
>> _______________________________________________<br>
>> midPoint mailing list<br>
>> <a href="mailto:midPoint@lists.evolveum.com" target="_blank">midPoint@lists.evolveum.com</a><br>
>> <a href="https://lists.evolveum.com/mailman/listinfo/midpoint" rel="noreferrer" target="_blank">https://lists.evolveum.com/mailman/listinfo/midpoint</a><br>
>><br>
>> ------------------------------<br>
>><br>
>> End of midPoint Digest, Vol 124, Issue 17<br>
>> *****************************************<br>
> _______________________________________________<br>
> midPoint mailing list<br>
> <a href="mailto:midPoint@lists.evolveum.com" target="_blank">midPoint@lists.evolveum.com</a><br>
> <a href="https://lists.evolveum.com/mailman/listinfo/midpoint" rel="noreferrer" target="_blank">https://lists.evolveum.com/mailman/listinfo/midpoint</a><br>
_______________________________________________<br>
midPoint mailing list<br>
<a href="mailto:midPoint@lists.evolveum.com" target="_blank">midPoint@lists.evolveum.com</a><br>
<a href="https://lists.evolveum.com/mailman/listinfo/midpoint" rel="noreferrer" target="_blank">https://lists.evolveum.com/mailman/listinfo/midpoint</a><br>
</blockquote></div>