0 votes

I've got a custom task to run and check if the license count falls below a threshold, then send an email if the former returns true. The issue is that the email is being sent twice for no apparent reason.

The code for the license count is on top. The custom email code is below that:

Check licnese count, return true if threshold below 100 image.png

Email code (with email redacted at the end): image.png

ago by (120 points)
0

Hello,

For troubleshooting purposes, please, provide a screenshot of the scheduled task including the Activity Scope section.

Also, please, provide us with a screenshot of the Multi-server environment dialog. The dialog displays how many Adaxes services you have and what their versions are. For information on how to view it, see https://www.adaxes.com/help/MultiServerEnvironment.

Lastly, please, provide both scripts in TXT format, not as screenshots.

You can post all the details here or send to us at support@adaxes.com.

0

image.png

image.png

image.png

Code 1

# The condition is met if $Context.ConditionIsMet is set to $True.
$Context.ConditionIsMet = $False

$threshold = 1000 # TODO: modify me

$serviceSettingsContainerPath = $Context.GetWellKnownContainerPath("ServiceSettings")
$serviceSettingsContainer = $Context.BindToObject($serviceSettingsContainerPath)

# Get number of users allowed by license
$productInfo = $serviceSettingsContainer.ProductInfo
$numberOfLicensedUsers = $productInfo.AllowedUserAccounts

if (($numberOfLicensedUsers -eq -2) -or ($numberOfLicensedUsers -eq -1))
{
    # Adaxes service is still calculating the number of enabled and not expired
    # users or the license is unlimited
    $Context.ConditionIsMet = $False
    return
}

# Get the number of enabled and not expired users
$numberOfEnabledAccounts = $productInfo.CalculateUserAccounts()

$Context.ConditionIsMet = ($numberOfLicensedUsers - $numberOfEnabledAccounts) -lt $threshold

Code 2

$serviceSettingsContainerPath = $Context.GetWellKnownContainerPath("ServiceSettings")
$serviceSettingsContainer = $Context.BindToObject($serviceSettingsContainerPath)

# Get number of users allowed by license
$productInfo = $serviceSettingsContainer.ProductInfo
$numberOfLicensedUsers = $productInfo.AllowedUserAccounts

# Get the number of enabled and not expired users
$numberOfEnabledAccounts = $productInfo.CalculateUserAccounts()

# Send email
$subject = "THIS IS A TEST Adaxes License Usage Alert THIS IS A TEST"
$bodytext = $Null
$body =
@"
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <meta name="x-apple-disable-message-reformatting">
  <title></title>
  <!--[if mso]>
  <noscript>
    <xml>
      <o:OfficeDocumentSettings>
        <o:PixelsPerInch>96</o:PixelsPerInch>
      </o:OfficeDocumentSettings>
    </xml>
  </noscript>
  <![endif]-->
  <style>
    table, td, div, h1, p {font-family: Arial, sans-serif;}
  </style>
</head>
<body style="margin:0;padding:0;">
  <table role="presentation" style="width:100%%;border-collapse:collapse;border:0;border-spacing:0;background:#ffffff;">
    <tr>
      <td align="center" style="padding:0;">
        <table role="presentation" style="width:602px;border-collapse:collapse;border:2px solid #f57e2c;border-spacing:0;text-align:left;">
          <tr>
            <td align="center" style="padding:40px 0 30px 0;background:#ffffff;border:2px solid #f57e2c;">
              <img src="logo.jpg" alt="" width="300" style="height:auto;display:block;" /><p style="font-size:33px;margin:20px 0 0 0;font-family:Arial,sans-serif;"><strong>Adaxes License count is approching the maximum value</strong></p>
            </td>
          </tr>
          <tr>
            <td style="padding:36px 30px 42px 30px;">
              <table role="presentation" style="width:100%%;border-collapse:collapse;border:0;border-spacing:0;">
                <tr>
                  <td style="padding:0 0 0 0;color:#153643;">
                    <h1 style="font-size:20px;margin:0 0 20px 0;font-family:Arial,sans-serif;">Please do the following to fix the issue:</h1>
                    <p style="margin:0 0 0 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;">- Reduce the amount of managed accounts</p>
                    <p style="margin:0 0 0 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;">- Purchase additional licenses</p><nr/><br/>
                    <p style="margin:0 0 0 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;">Current License Usage: $numberOfEnabledAccounts / $numberOfLicensedUsers licenses in use.</p>

                  </td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>
            <td style="padding:30px;background:#f57e2c;">
              <table role="presentation" style="width:100%%;border-collapse:collapse;border:0;border-spacing:0;font-size:9px;font-family:Arial,sans-serif;">
                <tr>
                  <td style="padding:0;width:50%%;" align="center">
                    <p style="margin:0;font-size:20px;line-height:16px;font-family:Arial,sans-serif;color:#ffffff;"><strong>Adaxes Automated Emails</strong><br/>
                    </p>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>
</html>
"@
$context.SendMail("[email redacted]", $Subject, $bodytext, $body)

1 Answer

0 votes
ago by (294k points)
selected ago by
Best answer

Hello,

Thank you for the provided details. Such a thing can happen if you have two managed domains in Adaxes. This way, the custom command will be executed twice (once per domain). For the notification to be delivered just once, remove All Objects from the Activity Scope and add just a single domain. It will not influence the scripts, but you will receive only a single email in case the condition is met.

0

That fixed it! Thank you. I was worried it wouldn't give me what I need for all of our domains, but the license count is still reflecting all numbers.

Appreciate it!

Related questions

0 votes
1 answer

Hey everyone, I hope you guys can help me out here. Our HR management is creating new users regulary and fill in the "Starting Date" date and time. There are different entry's ... Zeile:2 Zeichen:5 + try { + ~the closing "}" is missing or the typdefinition.

asked Sep 4, 2019 by rshergh (110 points)
0 votes
1 answer

I have a Business Rule in place that after a new user is created, will create an Exchange mailbox for the user, set the Retention Policy for the user, then send them a ... the correct email address for the user. Is this maybe just a timing issue or something?

asked May 16, 2014 by RickWaukCo (320 points)
0 votes
1 answer

How can I send more than just one report by email? I only have the option to schedule reports one by one in separate emails. Is it possible to send Overview reports that contain multiple reports in one?

asked Oct 1, 2021 by manomano (80 points)
0 votes
1 answer

Hello, i have created a custom attribute named user entry date. When a new user is created they need to enter the entry date with the create user command. The entry date ... buisness rule because it does not write any value in the sent email. Thank you, Fabian

asked Jun 7 by fabian.p (380 points)
0 votes
1 answer

We're utilizing the custom adaxes attributes for a few parts in our employee onboarding procedure. Among them is a step where we specify what buildings a user will need ... get all the values of "adm-CustomAttributeTextMultiValue1" to be sent out in an email?

asked Aug 9, 2021 by KruzGaffaney (50 points)
3,588 questions
3,277 answers
8,303 comments
548,076 users