Javascript Task queryFilter null results

I have a scheduled task in IDM that will get a list of users based on query filter then send email notifications (for password / account expirations). When running the query directly against IDM using the /managed/user?_queryFilter it returns the correct results. But, when running the below query in the task (which I am executing directly for testing via the rest api) it runs, but is not returning any data (and no errors in idm logs).

let query7 = {
    '_queryFilter': '/operationalData/suspendsOnTimestamp gt "' + warnDate6 + '" and /operationalData/suspendsOnTimestamp lt "' + warnDate8 + '" and effectiveStatus eq "active"'
}

logger.info("Query 7: " + JSON.stringify(query7));
let users7 = JSON.parse(openidm.query("managed/user", query7)).result;

logger.info("Users7: " + users7.toString());
if (users7) {
    users7.forEach((user) => {
        counter++;
        sendInactiveAccountNotification(user, "inactiveAccountNotification", "in 7 days");
    });
} else {
    logger.info("No users matched the 7 day warning so nothing to get sent out for 7 day warning notifications");
}

This is the queryFilter from the logs for testing / validation so know is correctly formatted.

INFO: Query 7: {"_queryFilter":"/operationalData/suspendsOnTimestamp gt \"2024-09-19T13:41:34.074Z\" and /operationalData/suspendsOnTimestamp lt \"2024-09-21T13:41:34.074Z\" and effectiveStatus eq \"active\""}

Any reason why a javascript task as part of a scheduler / job would not be able to see / get users from IDM?

Thanks
Nick

I’ll look at your solution when I get back into the office.
FWIW, this seems like a very resource intensive way of dealing with this need. Moreover, as a user, the last thing I want is more emailed notifications…. I’m not going to log into an application strictly to update a password. What I will do is login to an application to do some work, and if I’m forced to deal with password management, deal with it then.
Of course, I may be in the minority as when I’m not working, I rarely check emails anyways, lol.
Cheers. I’ll be back.

I think the issue is due to you prematurely closing a parenthesis:

I think you meant to include the result property of the response as an argument to JSON.parse. With the code as I read it now, you are attempting to access the result property of the object generated by JSON.parse and that would likely be null.

I believe the code you want is:
let users7 = JSON.parse(openidm.query("managed/user", query7).result);

edit: actually, the more I look at it, the less I think that would be the issue. You should still be able to access the result property, since that is in the response and therefore the generated object.

Have you tried adding the final argument to openidm.query? The list of fields should be refined to only the fields you want to use. Perhaps you have some fields on your managed/user object that are executing additional code, which in turn may be timing out the operation from within the script?

I actually found the issue and had nothing to do with the runtime / query, was a data issue with running the filter. Can actually get the result I need now.

But, while on the topic / javascript, I am trying to get the environment variables of the server using the process.env. but it is throwing an error saying process is not a function. Is there a binding to get the host environment variables in javascripts? @mwtech

Thanks
Nick

It sounds like this is what you are looking for - The identityServer variable :: IDM 7.5.0

1 Like

@mwtech that did the trick. Completed looked over the environment property option on this. Was successfully able to get this / replacements in the values. Appreciate the quick help on this.

Thanks
Nick

1 Like