Using DAL Queries in Form Builder

Hello,

does someone know how to use DAL Queries in Form Builder?

Actually I am looking for an example similar as shown in the Documentation, but using Form Builder. I wonder why the Documentation still refers the old forms???

Any input is very appreciable:)

Many thanks in advance und best regards,

Evanela

Tags:

  • Suggested Answer

    0

    Information about form builder is found in Administrator’s Guide to Form Builder but it is still not complete.

    First you have to setup the query in DAL and deploy it. If it returns some errors when being called later, try flushing the cache on IA.

    On the form builder you have 2 options: DN Query component or query from code. I rarely use the first one.

    The code is as follows. Note that if your query has no parameters, do not pass the last parameter at all. Passing empty braces wont work {}.

    IDVault.globalQuery("IDM", "/rest/access/query/global", "<dal_query_key>", [<list_of_return_attr>], {<json_of_query_parameters>})

    Real example:

    IDVault.globalQuery("IDM", "/rest/access/query/global", "CheckMail", ["CN"], {"mailToCheck": input, "username": currentUserCN})
    .then(result => {
        console.log(result);
    })

    I hope this answers your question.

    Best regards, Nik

  • 0 in reply to 

    Hi Nik,

    thanks a lot for your answer. This is very helpful. 

    One more question:

    I was thinking to use the "Select" component of Form Builder and populating it with users from a global query and than be able to search by user name or userId.

    How to configure such component and populate with query data?

    Thanks and best regards,

    Evanela

  • Verified Answer

    +1 in reply to 

    Hi,


    Either you calculate the display value in a dalCalculatedAttribute on the entity, and then you can set the value like this:

    function yourSelectField_CustomDefaultValue () {
            IDVault.globalQuery('IDM', '/rest/access/query/global', 'getUsers', ['DALCalculatedAttribute'], { 'department': data.departmentField })
                .then(function (resp) {
                    instance.setFieldValue(resp, 'dn', 'DALCalculatedAttribute')
                })
                .catch(function (error) { console.log(error) })
    }

    You could also use the dynamic entity component if you don't need any query parameters.

    Or you can calculate the display value in the form like this:

    function yourSelectField_CustomDefaultValue () {
            IDVault.globalQuery('IDM', '/rest/access/query/global', 'getUsers', ['FullName', 'userID'], { 'department': data.departmentField })
                .then(function (resp) {
                    resp = resp.map(user => ({
                        dn: user.dn,
                        displayValue: (user.FullName + " - " + user.userID )
                    }))
                    instance.setFieldValue(resp, 'dn', 'displayValue')
                })
                .catch(function (error) { console.log(error) })
    }

    Best regards,
    Philip

  • 0 in reply to 

    I was never able to find a solution for such a requirement on my own, but my ingenious colleague (whom I am not calling out by name, but will make sure he is forwarded this comment) achieved exactly what you are talking about by firstly setting select component data to custom and to present data from another hidden component and then adding a logic to any component that executes on trigger "formLoad" and configures a listener on the actual html component reacting to user input and doing all the querying and setting the updated values on that hidden component.
    We tweaked it with choices.js properties "searchResultLimit: 10" (or whatever number you need) and "searchEnabled: false" (the last one behaves differently in IDM, so consider checking if it stops the component to filter/sort the provided data)

    You will find an example of this solution here:
    https://jsfiddle.net/qqo1a/frjq8kz0/47/

    Please share if you find any crafty way to make it better.

  • Suggested Answer

    0 in reply to 

    Thanks a lot Philip, 

    this is very helpful, it works Slight smile

    Best regards, 

    Evanela