<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi,</p>
    <p>The documentation was not updated.<br>
    </p>
    <p>Something like that :<br>
    </p>
    <blockquote>
      <p><i><span>assignmentDelta</span> =
          midpoint.deltaFor(UserType.class)<br>
          <span><br>
          </span></i></p>
      <p><i><span></span></i><span> for (AssignmentType assign :
          user.getAssignment()) {</span></p>
      <p><span>         ...<br>
        </span></p>
      <p><i><span>        assignmentDelta</span> = <span>assignmentDelta</span>.item(<span>UserType.F_ASSIGNMENT</span>).delete(<span>assign</span>)
          <br>
        </i></p>
      <p><i><span>         ...<br>
          </span></i></p>
      <p><i><span>}<br>
          </span></i></p>
      <p><i><span>myDeltas</span> = <span>assignmentDelta</span>.asItemDeltas()<br>
          modelContext.getFocusContext().swallowToSecondaryDelta(my<span>Deltas</span>)</i></p>
      <p><i>modelContext.rot()<br>
        </i></p>
    </blockquote>
    <p><br>
    </p>
    <p>You should call only one time "swallowToSecondaryDelta()": put it
      out of the "for" iteration.<br>
    </p>
    <p>Not sure that "assign.clone()" works: maybe (not sure) you should
      use only "assign".<br>
    </p>
    <p>Best regards et bon courage :)<br>
    </p>
    <div class="moz-cite-prefix">Le 12/10/2023 à 11:58, Markus Calmius
      via midPoint a écrit :<br>
    </div>
    <blockquote type="cite"
cite="mid:swEC6ps0RQPo95QBtxoY8erxVUxU-FqOov8dHOxYW27LOhahXUCQXUfYeKdOUMUMhg_Y2_qjDkLj6MrWO_exyo_d8_AL0GNyOjedDrgMckk=@proton.ch">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <div style="font-family: Arial, sans-serif; font-size: 14px;">Hi,</div>
      <div style="font-family: Arial, sans-serif; font-size: 14px;"><br>
      </div>
      <div style="font-family: Arial, sans-serif; font-size: 14px;">I am
        trying to figure out how to make sure all roles are unassigned
        when a user is removed or disabled from HR. </div>
      <div style="font-family: Arial, sans-serif; font-size: 14px;">I've
        found: <span><a target="_blank"
            rel="noreferrer nofollow noopener"
href="https://docs.evolveum.com/midpoint/reference/concepts/clockwork/scripting-hooks/"
            moz-do-not-send="true" class="moz-txt-link-freetext">https://docs.evolveum.com/midpoint/reference/concepts/clockwork/scripting-hooks/</a> which
          contain Example 1 that should do the trick.</span></div>
      <div style="font-family: Arial, sans-serif; font-size: 14px;"><span>Although,
          it doesn't quite work on 4.7.2 it seems, I get: "<span>Expression
            error: Groovy Evaluation Failed: No such property:
            ContainerDelta for class: (new)_</span>"</span></div>
      <div style="font-family: Arial, sans-serif; font-size: 14px;"><span><br>
        </span></div>
      <div style="font-family: Arial, sans-serif; font-size: 14px;"><span>Two
          questions:</span></div>
      <div style="font-family: Arial, sans-serif; font-size: 14px;">
        <ol
data-editing-info="{"orderedStyleType":1,"unorderedStyleType":1}"
          data-listchain="__List_Chain_88">
          <li style="list-style-type: "1. ";"><span><span></span>is
              there an easier way?</span></li>
          <li style="list-style-type: "2. ";">trying to figure
            out what is wrong is not super easy, it's been years since I
            actually coded. Any guidance is greatly appreciated. I
            assume the <span
style="text-align: start; display: inline !important; background-color: rgb(255, 255, 255);">createModificationDelete
              has changed some input parameters </span></li>
        </ol>
      </div>
      <div style="font-family: Arial, sans-serif; font-size: 14px;">
        <div><br>
        </div>
        <div><span><span><span>I'm testing the script in the query
                playground with one disabled user. </span></span></span></div>
        <expression></div>
      <div style="font-family: Arial, sans-serif; font-size: 14px;">
        <div><span>    <script></span></div>
        <div><span> <code></span></div>
        <div><span>            import
            com.evolveum.midpoint.xml.ns._public.common.common_3.*;</span></div>
        <div><span>            import com.evolveum.midpoint.prism.*;</span></div>
        <div><br>
        </div>
        <div><span>    UserType user = (UserType)
            midpoint.searchObjectByName(UserType.class, '<redacted
            username>');</span></div>
        <div><span>    ActivationStatusType administrativeStatus =
            user.getActivation().getEffectiveStatus();</span></div>
        <div><span>    if (administrativeStatus ==
            ActivationStatusType.DISABLED) {</span></div>
        <div><span>            for (AssignmentType assign :
            user.getAssignment()) {</span></div>
        <div><span>                    changed = false;</span></div>
        <div><span>                    assignmentDelta =
            ContainerDelta.createModificationDelete(UserType.F_ASSIGNMENT,
            UserType.class, prismContext, assign.clone());</span></div>
        <div><span>                   
            modelContext.getFocusContext().swallowToSecondaryDelta(assignmentDelta);</span></div>
        <div><span>                    changed = true;</span></div>
        <div><span>                }</span></div>
        <div><span>                if (changed) {</span></div>
        <div><span>                    modelContext.rot(); // this makes
            Projector to recompute the model context</span></div>
        <div><span>                }</span></div>
        <div><span>    }</span></div>
        <div><span> </code></span></div>
        <div><span> </script></span></div>
        <div><span></expression></span></div>
        <span></span><br>
      </div>
      <div style="font-family: Arial, sans-serif; font-size: 14px;">Thanks
        in Advance</div>
      <div class="protonmail_signature_block"
        style="font-family: Arial, sans-serif; font-size: 14px;">
        <div class="protonmail_signature_block-user"> Markus</div>
        <div
class="protonmail_signature_block-proton protonmail_signature_block-empty">
        </div>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
midPoint mailing list
<a class="moz-txt-link-abbreviated" href="mailto:midPoint@lists.evolveum.com">midPoint@lists.evolveum.com</a>
<a class="moz-txt-link-freetext" href="https://lists.evolveum.com/mailman/listinfo/midpoint">https://lists.evolveum.com/mailman/listinfo/midpoint</a>
</pre>
    </blockquote>
  </body>
</html>