1. Automatic notifications to users outside ObjectGears

    Article: AN0002448Updated: 21.11.2020

    In this article we will explain how we can let ObjectGears to send notifications to users who do not have ObjectGears account.

    In our example we have a class with applications (business-application) with properties support_to (date) and analysts (reference to another class ms-ad-users). Relationship of the two classes is depicted in the following scheme.

    We will use automatic time operations to check field support_to and send notification to colleagues stated in the column analysts well in advance as the date approaches.

    If there is reference to ObjectGears users in the field analysts, we could set the recipients easily in the time operation by selecting this column.

    However, notification recipients will not be ObjectGears users. Instead recipients will be represented just by records from another class at which we will have email. Sending notification can be secured in two ways. By a script in a time operation above the class business-application, that will find out emails from the class ms-ad-users or by a query that will return for each application emails separated by comma in a special column and by a time operation above this query.

    Option No.1 - Script in time operation above class

    We will set the filter in the time operation for records where the field analysts is not null. In the tab with actual operations we will use following script.

    /*the script examines the multiple classlink Analysts, that leads to class ms-ad-users - emails are in column e-mail
    It will send notification end_of_support_reminder and links the sent email to the record of the given application.*/

    var drl = OGActualDataRow.GetDR('analysts');
    if ( drl != null && drl.Count > 0)
      //email preparation
      var m = OG.Email.CreateMessage();

      var isAnyEmail = false;
      for( var i = 0; i < drl.Count; ++i)
        var email = drl[i]['e-mail'];
        if ( !OG.IsNull(email))
          isAnyEmail = true;

      if (isAnyEmail)
        var mIt = OG.Model.GetByCode('it');
        m.Notification = OG.Notification.GetAll().GetDefaultByCode( mIt.Id, 'end_of_support_reminder');

        //linking email to the record of application
        m.AssignEmailForDataRow = OGActualDataRow;

        m.SendEmailAsOne = true; //send as a single email
        //m.SendEmailAsOne = false; //send individual emails to each recipient

        //linking email to the time operation as originator of sending
        m.OwnerType = OG.Email.EmailOwnerType_AutomaticTimeOperationSend;
        m.OwnerId = OGActualAto.Id;


    Option No.2 - Query returning emails and time operation above this query

    In this case we will transform data from both classes into a query and then we will set up time operation above this query easily. SQL of the query:

    SELECT t.*
      SELECT ba.id, ba.support_to, CONVERT(varchar(10),ba.id) as ba_id, ba.name,
      ( STUFF((
        SELECT ';' + us.[e-mail] AS [text()]
        FROM {{:class.ms-ad-users:}} us
        INNER JOIN DataRow{{:class.business-application.id:}}_{{:class.ms-ad-users.id:}}Link l
        ON l.ColumnClassDefId = {{:class.business-application.column.analysts.id:}} and l.ReferentionId = ba.Id
        WHERE us.Deleted is null
        AND us.id = l.LinkReferentionId
        /*ORDER BY f.Id*/
        FOR XML PATH ('')
        ), 1, 1, '')
      ) emails
      FROM {{:class.business-application:}} ba
    ) t
    WHERE t.emails is not null