Skip to content

Formula Examples

Sending email with generated PDF as an attachment

$attachmentId = ext\pdf\generate(
    'Quote', entity\attribute('id'), 'copy-pdf-template-id-here', 'test.pdf'
);

$emailId = record\create('Email',
    'to', entity\attribute('emailAddress'),
    'attachmentsIds', list($attachmentId)
);

// applying email template
ext\email\applyTemplate($emailId, 'copy-email-template-id-here');

ext\email\send($emailId);

Push Notification Examples

The following examples demonstrate different scenarios for sending Push Notifications to team members assigned to a Case. These formulas are especially useful for ensuring that the Case Team stays updated on any status changes or messages posted to streams by portal users.

The formula example below demonstrates sending a Push Notification to all Users on a Team assigned to a Case when the Portal User updates the Case Status.

//Define the url to open when a notification is opened
$url = string\concatenate(util\getApplicationParam('ApplicationUrl'), '/#Case/view/', entity\attribute('id'));

// If portal user updates status send pushnotification to all users on teams asssigned to this case.
ifThen(
    env\userAttribute('type') == 'portal' && entity\isAttributeChanged('status')
, 
    util\SendNotificationToTeamsOnRecord(
        entity\attribute('id'), 
        'Case', 
        string\concatenate('Portal user ', env\userAttribute('name'), ' has updated case ', entity\attribute('number')), 
        string\concatenate('Status updated from ', entity\attributeFetched('status'), ' to ', entity\attribute('status')), 
        'url', $url
    );
);

The formula example below demonstrates sending a Push Notification to all members of the assigned team.

// If portal user creates a case assign a default team and then send pushnotification to all users on the team
ifThen(
    env\userAttribute('type') == 'portal' && entity\isNew()
, 
    //query for the id of Compliance Team
    $defaultTeamId = record\findOne('Team', 'createdAt', 'desc', 'name=', 'Compliance Team');

    entity\addLinkMultipleId('teams', $defaultTeamId);

    util\SendNotificationToTeam(// can not use SendNotificationToTeamsOnRecord as record is not yet saved
        $defaultTeamId, 
        string\concatenate('Portal user ', env\userAttribute('name'), ' has created case ', entity\attribute('number')), 
        entity\attribute('name'),
        'url', $url
    );
);

The formula example below demonstrates sending a Push Notification to all members of the assigned team.

// If portal user updates a case send pushnotification to all users on teams asssigned to this case.
// Normally the 'status' field is read only and can only be updated via the button process. If Strict Portal 
// controls are enabled this should not double up with the status push notificaiton. However, you may need 
// to modify this if you are allowing portal users to edit the 'status' directly.
ifThen(
    env\userAttribute('type') == 'portal' && 
    !entity\isNew() && //only for updates
    !entity\isAttributeChanged('mostRecentPostId') //prevent posts stream from sending this notificaiton, this will be covered below.
, 
    util\SendNotificationToTeamsOnRecord(
        entity\attribute('id'), 
        'Case', 
        string\concatenate('Portal user ', env\userAttribute('name'), ' has updated case ', entity\attribute('number')), 
        entity\attribute('name'),
        'url', $url
    );

);

The formula example below demonstrates sending a Push Notification to all Users on a Team assigned to a Case when the Portal User posts a message on the Stream.

// If portal user posts a message in the stream on a case send push notification to all users on teams asssigned to this case.
ifThen(
    env\userAttribute('type') == 'portal' && 
    !entity\isNew() &&
    entity\isAttributeChanged('mostRecentPostId')
, 
    util\SendNotificationToTeamsOnRecord(
        entity\attribute('id'), 
        'Case', 
        string\concatenate('Portal user ', env\userAttribute('name'), ' has posted on case ', entity\attribute('number')), 
        entity\attribute('name'),
        'url', $url
    );

);

See also


Top