How do I look up a manage/user from a workflow form

This topic has 6 replies, 3 voices, and was last updated 5 years, 4 months ago by Tom Wood.

  • Author
    Posts
  • #10619
     Morten Lømo
    Participant

    I have a workflow. It starts with a form (nUCStartForm.xhtml). The user types in a user, e.g. scarter. How do I lookup this user (scarter) in the managed/user repository in OpenIDM (on the server side) and return the details of this user (first name, last name, ..) to the same form file (nUCStartForm.xhtml) on the client side? Do I have to make an endpoint for this? How will the JavaScript code in the form file look like?

    Thanks for any help.

    Morten

    #10635
     Tom Wood
    Participant

    Assuming that you know the _id value of the managed object you’re looking for, the whole user object could be retrieved using openidm.read(“managed/user/scarter”). Alternatively, you could use openidm.query if you need to search based on some other parameters via a queryFilter or similar. From this point, you should be able to extract the information you need from the full object which has been returned. There is some additional information around the openidm.[method] scripting objects available within the OpenIDM Integrator’s Guide which may prove useful.

    If you’re looking for an example around the use of workflows, I would recommend unzipping the contractorOnboarding.bar file within ‘../openidm/samples/workflow/workflow’ to view the underlying BPMN20.xml file which may also help.

    #10642
     Morten Lømo
    Participant

    Thanks for your help. But the openidm.read() function is for the server side, no? I also need something on the client side? The client side has received the form code (nUCStartForm.xhtml), which is a part of the workflow. It consists of both html and javascript code. Here I need to add som Ajax code or similar, if I am correct, so that after the user has filled in the user-id, it can send the user-id to the server side and wait for the respons from the server side. How do I write this Ajax or similar code (to be put into the form file: nUCStartForm.xhtml) and how can it reach openidm.read() or something similar on the server side?

    Thanks
    Morten

    • This reply was modified 5 years, 5 months ago by Morten Lømo.
    • This reply was modified 5 years, 5 months ago by Morten Lømo.
    #10711
     markg
    Participant

    Have you looked at https://forgerock.org/openidm/doc/bootstrap/integrators-guide/index.html#query-filters ? If you know the userName, you can query the /managed/user endpoint and return the information you want.

    #10821
     Morten Lømo
    Participant

    Thanks for help. Here are some more details on what I am struggling with. I am able to do this curl command:

    
    Mortens-iMac:samples Morten$ curl --header "X-OpenIDM-Username: openidm-admin" --header "X-OpenIDM-Password: openidm-admin" --request GET "http://localhost:8080/openidm/managed/tnsystem?_queryFilter=systemName+eq+'FHS'&_fields=rights" | jq .
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100   221    0   221    0     0   1256      0 --:--:-- --:--:-- --:--:--  1262
    {
      "result": [
        {
          "_id": "c2b89139-0ba0-4803-92a9-30416fbd9d37",
          "_rev": "1",
          "rights": "admin;readOnly"
        }
      ],
      "resultCount": 1,
      "pagedResultsCookie": null,
      "totalPagedResultsPolicy": "NONE",
      "totalPagedResults": -1,
      "remainingPagedResults": -1
    }
    

    Now I would like to do the same thing from Javascript (running on the client side). I have written the following:

    
    var url = "http://localhost:8080/openidm/managed/tnsystem?_queryFilter=systemName+eq+'FHS'&_fields=rights"; 
    
    xmlhttp.open("GET", url, true);
    xmlhttp.setRequestHeader("X-OpenIDM-Username", "openidm-admin");
    xmlhttp.setRequestHeader("X-OpenIDM-Password", "openidm-admin");
    xmlhttp.send();
    
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.status == 200) {
          alert("Data received = ");
        }
        else
          alert("Error received = ");
          alert(xmlhttp.status);
          alert(xmlhttp.statusText);
    }; 
    

    I get “Error received” and status=0. Do you know what I do wrongly? Or should I be using a framework on top of plain JavaScript?

    Thanks for any help.

    Morten

    • This reply was modified 5 years, 4 months ago by Morten Lømo.
    #10823
     Morten Lømo
    Participant

    I forgot this at the beginning:

    
    var xmlhttp = new XMLHttpRequest();
    
    #10850
     Tom Wood
    Participant

    Hi Morten,

    I believe you’ll need the ‘Content-Type: application/json’ header as well here, although I’m unsure if that will resolve the problem you’re hitting. Is the use of the openidm-admin user intended for the final product of this scripting or only during testing? I would be slightly wary of allowing an end-user access to these credentials unintentionally.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

©2021 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?