<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Vorformatiert Zchn";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
span.HTMLVorformatiertZchn
        {mso-style-name:"HTML Vorformatiert Zchn";
        mso-style-priority:99;
        mso-style-link:"HTML Vorformatiert";
        font-family:Consolas;
        mso-fareast-language:EN-US;}
span.E-MailFormatvorlage23
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1136948998;
        mso-list-type:hybrid;
        mso-list-template-ids:1349543522 861947622 67567619 67567621 67567617 67567619 67567621 67567617 67567619 67567621;}
@list l0:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;
        mso-fareast-font-family:Calibri;
        mso-bidi-font-family:"Times New Roman";}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi Hsin-Fang,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">you need to use “range” in your inbound mapping. It is described in the documentation:<o:p></o:p></span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span lang="EN-US"><a href="https://docs.evolveum.com/midpoint/reference/expressions/mappings/inbound-mapping/#range-of-inbound-mappings">https://docs.evolveum.com/midpoint/reference/expressions/mappings/inbound-mapping/#range-of-inbound-mappings</a><o:p></o:p></span></li></ul>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">With range you can replace all values from source, instead of just add new values.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Kind regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Fabian<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black;mso-fareast-language:DE">Von:
</span></b><span style="font-size:12.0pt;color:black;mso-fareast-language:DE">Hsin-Fang Hsu <hsin-fang.hsu@itconcepts.ch><br>
<b>Datum: </b>Dienstag, 27. Juli 2021 um 22:51<br>
<b>An: </b>MidPoint Mailing List <midpoint@lists.evolveum.com><br>
<b>Betreff: </b>[midPoint] how to remove values from attributes whose maxOccurs=unbounded<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="mso-fareast-language:DE"><o:p> </o:p></span></p>
</div>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">Dear all,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">I have an extension attribute (whose maxOccurs=” unbounded”) called “Access Requests”.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">I want to modify and even remove some of its value based on the value of my connected resource.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">For example, the GUI list shows:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><img border="0" width="806" height="104" style="width:8.3958in;height:1.0833in" id="Picture_x0020_1" src="cid:image001.png@01D7838E.AAE83BA0"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">And I want to remove APP_HASTUS_ADD_PENDING from the list.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">Does anyone know how I can do this with script?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">-----------------------------------------------------------------------------------------------------------------------------------------------------------<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">Here is what I tried but failed.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">The main concept of what I tried is the following 4 steps:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">(1) I can get all values shown in the GUI list
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">(i.e., list_access_request = [‘APP_BASEWARE’, ‘APP_HASTUS_ADD_PENDING’, ‘APP_HASTUS’])<o:p></o:p></span></p>
<pre style="background:#2B2B2B"><span style="color:#A9B7C6;background:#364135">def list_access_request = ObjectTypeUtil.getExtensionPropertyValues(focus, new javax.xml.namespace.QName('http://midpoint.xxx.oo/xml/ns/extended-userobject', 'accessRequests'))</span><span style="color:#A9B7C6"><o:p></o:p></span></pre>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">(2) I use this to remove all current values
<o:p></o:p></span></p>
<pre style="background:#2B2B2B"><span style="color:#A9B7C6;background:#364135">user.setExtension(new ExtensionType())</span><span style="color:#A9B7C6"><o:p></o:p></span></pre>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">(3) list_after_reset shows that the value indeed become empty afterwards.<o:p></o:p></span></p>
<pre style="background:#2B2B2B"><span style="color:#A9B7C6;background:#364135">def list_after_reset = ObjectTypeUtil.getExtensionPropertyValues(focus, new javax.xml.namespace.QName('http://midpoint.xxx.oo/xml/ns/extended-userobject', 'accessRequests'))</span><span style="color:#A9B7C6"><o:p></o:p></span></pre>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">(4) I removed some values in list_access_request and finally return list_access_request
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">Even the return value list_access_request is correct, the list shown in the GUI is still wrong: new values that wasn’t in the GUI list can be added but it’s not possible to remove any value from
 the GUI list. <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">This is the script of what I tried in the attribute of the resource:<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#2B2B2B"><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"><attribute><br>
    <</span><span style="font-size:10.0pt;font-family:"Courier New";color:#9876AA">c</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A">:ref
</span><span style="font-size:10.0pt;font-family:"Courier New";color:#BABABA">xmlns:</span><span style="font-size:10.0pt;font-family:"Courier New";color:#9876AA">ri</span><span style="font-size:10.0pt;font-family:"Courier New";color:#6A8759">=<a href="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3">http://midpoint.evolveum.com/xml/ns/public/resource/instance-3</a></span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A">></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">ri:lifecycle_state</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></</span><span style="font-size:10.0pt;font-family:"Courier New";color:#9876AA">c</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A">:ref><br>
    <displayName></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">lifecycle state is</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></displayName><br>
    <limitations><br>
        <access><br>
            <read></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">true</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></read><br>
            <add></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">true</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></add><br>
            <modify></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">true</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></modify><br>
        </access><br>
    </limitations><br>
    <tolerant></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">true</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></tolerant><br>
    <exclusiveStrong></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">false</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></exclusiveStrong><br>
    <inbound><br>
        <authoritative></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">true</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></authoritative><br>
        <exclusive></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">false</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></exclusive><br>
        <strength></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">strong</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></strength><br>
        <source><br>
            <name></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">requested_role</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></name><br>
            <path></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">$projection/attributes/ri:requested_role</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></path><br>
        </source><br>
        <source><br>
            <name></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">userName</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></name><br>
            <path></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">$user/name</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></path><br>
        </source><br>
        <expression><br>
            <script><br>
                <code><span style="background:#364135"><br>
                    </span></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6;background:#364135">import com.evolveum.midpoint.schema.util.ObjectTypeUtil<br>
<br>
                    // getCurrent accessRequests<br>
                    def list_access_request = ObjectTypeUtil.getExtensionPropertyValues(focus, new javax.xml.namespace.QName('http://midpoint.xxx.oo/xml/ns/extended-userobject', 'accessRequests'))<br>
<br>
                    // remove unused requests<br>
                    if (list_access_request == null) {<br>
                        list_access_request = []<br>
                    } else {<br>
                        if (list_access_request.indexOf(requested_role) != -1) {<br>
                            list_access_request.remove(list_access_request.indexOf(requested_role))<br>
                        }<br>
                    }<br>
<br>
                    // modify request based on input<br>
                    if (input == 0 | input == 1) {<br>
                        list_access_request.add(userName + '_' + requested_role + '_ADD_PENDING')<br>
                    } else if (input == 2) {<br>
                        list_access_request.add(requested_role)<br>
                    }<br>
<br>
<br>
                    // reset accessRequests List<br>
                    user.setExtension(new ExtensionType())<br>
                    def list_after_reset = ObjectTypeUtil.getExtensionPropertyValues(focus, new javax.xml.namespace.QName('http://midpoint.tpg.ch/xml/ns/extended-userobject', 'accessRequests'))<br>
                    log.info('-----after clean up, accessRequests  is: ' + list_after_reset.toString())<br>
<br>
                    log.info('------return accessRequests is: ' + list_access_request.toString())<br>
                    return list_access_request<br>
<br>
                </span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></code><br>
            </script><br>
        </expression><br>
        <target><br>
            <path></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6">$user/extension/accessRequests</span><span style="font-size:10.0pt;font-family:"Courier New";color:#E8BF6A"></path><br>
        </target><br>
    </inbound><br>
</attribute></span><span style="font-size:10.0pt;font-family:"Courier New";color:#A9B7C6"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">This is the definition of the extension part<o:p></o:p></span></p>
<pre style="background:#2B2B2B"><span style="color:#E8BF6A"><</span><span style="color:#9876AA">xsd</span><span style="color:#E8BF6A">:element </span><span style="color:#BABABA">name</span><span style="color:#6A8759">="accessRequests" </span><span style="color:#BABABA">type</span><span style="color:#6A8759">="xsd:string" </span><span style="color:#BABABA">minOccurs</span><span style="color:#6A8759">="0" </span><span style="color:#BABABA">maxOccurs</span><span style="color:#6A8759">="unbounded"</span><span style="color:#E8BF6A">><br>    <</span><span style="color:#9876AA">xsd</span><span style="color:#E8BF6A">:annotation><br>        <</span><span style="color:#9876AA">xsd</span><span style="color:#E8BF6A">:appinfo><br>            <</span><span style="color:#9876AA">a</span><span style="color:#E8BF6A">:indexed></span><span style="color:#A9B7C6">true</span><span style="color:#E8BF6A"></</span><span style="color:#9876AA">a</span><span style="color:#E8BF6A">:indexed><br>            <</span><span style="color:#9876AA">a</span><span style="color:#E8BF6A">:displayName></span><span style="color:#A9B7C6">Access Requests</span><span style="color:#E8BF6A"></</span><span style="color:#9876AA">a</span><span style="color:#E8BF6A">:displayName><br>            <</span><span style="color:#9876AA">a</span><span style="color:#E8BF6A">:displayOrder></span><span style="color:#A9B7C6">113</span><span style="color:#E8BF6A"></</span><span style="color:#9876AA">a</span><span style="color:#E8BF6A">:displayOrder><br>        </</span><span style="color:#9876AA">xsd</span><span style="color:#E8BF6A">:appinfo><br>    </</span><span style="color:#9876AA">xsd</span><span style="color:#E8BF6A">:annotation><br></</span><span style="color:#9876AA">xsd</span><span style="color:#E8BF6A">:element></span><span style="color:#A9B7C6"><o:p></o:p></span></pre>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">Thank you very much for your help in advance!<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">Best regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt">Hsin-Fang<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:14.0pt"><o:p> </o:p></span></p>
</div>
</body>
</html>