Featured

    Featured Posts

  • How to use Shortcut keys in USD
  • Create Timer behavior with action calls

Using Notifications in USD 2.2

I would say, This post is an extension to Neil’s USD – Notifications post (link). I want to use it with one another kind-of real world scenario. Let’s say being a Call center Manager, you want to display an important message – “XYZ application processing has been stopped for today, Please make sure you are not accepting calls for this application” to all your agents.


Before USD 2.2, Maybe you can go with DisplayMessage action of CRM Global Manager but not a foolproof one. But the new Notifications in USD2.2 would help a lot in achieving this scenarios more efficiently.


Consider the same scenario and we want to show it whenever the user starts a session and user will have flexibility to stop it. Let's see the steps involved.
  1. Create the hosted control
  2. Create the required “FORM” record with XAML
  3. Create the action calls required to Open the notification, Close the notification, Don’t show again notification
  4. Create the custom event for Don’t show notification


Create the Hosted Control

Note: This step is not required if you have OOB configurations in your Org. If you have OOB configurations, you can use “GlobalNotification” control.


Create a new Hosted control with name “GlobalNotification” and type as “PopupNotificaiton” as shown below. Make sure the control is marked as Global as shown below.

Create Custom Event to handle “Don’t Show again”

Navigate to Events section of the GlobalNotification hosted control, create a new Event with name “DontShowAgain” as shown below.


After save&close, this is how you should see the events of GlobalNotification hosted control

Create a new FORM record for the UI of the message box

Navigate to Unified Service Desk >> Forms and Click on New to create new Form record.
Give the form some meaningful name. In my case I have created with a name “ShowNotification” with the following XAML. Make a note of the Name of the form, later on we are going to use it in action calls as well.


Note: Following is the XAML I have created which I found looking nice :). But you may find it offbeat, make yourself comfortable in making the changes required for your environment, but keep in mind if you are changing any event names/command parameters/replacement parameters etc. then you have to change accordingly further in action calls.

<Border xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:CCA="clr-namespace:Microsoft.Crm.UnifiedServiceDesk.Dynamics;assembly=Microsoft.Crm.UnifiedServiceDesk.Dynamics"
    xmlns:Converters="clr-namespace:USDConverters;assembly=USDConverters"
    BorderBrush="Black" Background="DarkGray">
            <Grid Height="auto" Width="600" Margin="3" Background="White">
                <Grid.Resources>
                    <!--<Converters:CommandParameterConverter x:Key="CommandParameterConverter" />-->
                </Grid.Resources>
                <Grid.RowDefinitions>
                    <RowDefinition Height="20" />
                    <RowDefinition Height="100" MaxHeight="100" />
                    <RowDefinition Height="40"/>

                </Grid.RowDefinitions>
                <Grid Background="#444444" Grid.Row="0" Height="auto">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="60*"/>
                        <ColumnDefinition Width="40*"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Foreground="White" Grid.Column="0" 
                               Margin="9,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" 
                               FontSize="12" TextWrapping="Wrap" FontFamily="Calibri">
                        <Run Text=":: Message ::" />
                    </TextBlock>

                </Grid>
                <Grid Grid.Row="1" Height="auto">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="10">
                        <TextBlock Foreground="Black" Grid.Column="0" TextWrapping="Wrap"  FontFamily="Calibri" >
                            <Run FontSize="16" Text="[[$Global.Message]+]"  />
                        </TextBlock>
                    </ScrollViewer>

                </Grid>

                <Grid Grid.Row="2" Background="#F0F0F0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Button Grid.Column="1"  Height="22" Width ="120" Background="Green" Foreground="Black"
                        Command="CCA:ActionCommands.UIIEvent" 
                        CommandParameter="Ok">
                        <Button.Content>
                            <Bold>OK</Bold>
                        </Button.Content>
                    </Button>
                    <Button Grid.Column="0"  Height="22" Width ="120" Background="Green" Foreground="Black"
                        Command="CCA:ActionCommands.UIIEvent" 
                        CommandParameter="DontShowAgain">
                        <Button.Content>
                            <Bold>Don't Show again</Bold>
                        </Button.Content>
                    </Button>
                </Grid>
            </Grid>
        </Border>

And this is how the Form record looks like.


And this is how the design of it looks like.

Now, let's create Action calls

To Open notification: Create a new Action call with the following details.


Name
Show Notification Message (General)
Order
100
Hosted Control
GlobalNotification
Action
Show
Data
formName = ShowNotification
top = 40
left = 30
Preview


To Close Notification: We need to handle the notification closing if we are working with custom event handlers. Remember we have created a custom event in step 1 for DontShowMessageAgain, we are going to attach this close notification action call later to the event. Create a new action call with the following details.


Name
Close Notification
Order
10
Hosted Control
GlobalNotification
Action
Close
Preview
Action call to Create User Setting for Don’tShowagain: Once when user presses don’t show again, we will create a user setting record which we can use in the action call as a condition so that the message won’t popup to user again.


Name
Set user settings for DontShowNotification
Order
20
Hosted Control
CRM Global Manager
Action
SaveSetting
Data
name=DontShowNotificationAgain
value=1
Preview


Now, the last step before closing the action calls, to add the condition for “Show Notification Message (General)”. This action call should only fire

  1. When there is a message to show. The idea is to place the message in the USD Options entity as a setting of USD. This message will then become part of USD’s $Global replacement parameter.
  2. When there is no user settings record for DontShowNotificationAgain.  Basically, when we call the Save Setting action, it would create a new record in User Settings record and further would be available as part of USD’s $Setting replacement parameters.

So, let’s open the “Show Notification Message (General)” action call which we created previously and add the condition as shown below.
Condition
"[[$Global.Message]+]" !="" && "[[$Settings.DontShowNotificationAgain]g+]" !="1"


Finally the action call should look like:


Now, let’s attach the action calls to their corresponding events.


As we want to show the message every time a session is started, The “Show Notification Message (General)” should be attached to “SessionNew” event as shown below.


When user clicks on the “DontShowAgain” button in the UI, we should set the setting and close the message box. So, let’s add both “Set user settings for DontShowNotification” and “Close Notificaton” to the “DontShowAgain” event which we created in step1 as shown below.


That’s it, we have almost assembled all bits. The left out part is the message that we want to show. Let’s create a new Option record. Navigate to Unified service desk >> Options >> Click New and create a new Option record with the following information.


Global Options
Others
Name
Message
value
XYZ application processing has been stopped for today, Please make sure you are not accepting calls for this application
Preview


All right, we are all set to go. Open the USD and start a new session and check, you should be able to see something like this.


Observe that, if you simply click OK and start another session, it will show the same message again. But If you click on Don’t Show Again button, then the message will not come again for further sessions. If you check the user settings now, you should be able to see a record got created automatically with DontShowMessageAgain value set to 1.


Deleting this record, will pops up the message again to user. Hope this helps in understanding the uses of this Pop up notifications. I can see lot of benefits with this kind of popup messages. The good part of it is, it’s a no code solution again and any admins can easily configure the required messages. Except for the XAML which I think we don’t need to change all the times, just setup once and use the same everywhere :).

I’m exploring further on how to make it time bounded by combining it with my previous post of Javascripts in conditions. Will share you the details further if I found it is interesting. Till then, Happy new year :)

Javascript in “Conditions” of Action calls & WNR

One who have got some exposure on USD, would have definitely observed the big “Condition” box in Action Calls & Window navigation rules (and may be any other entities as well which I haven’t observed so far) where we can mention condition expression which will be evaluated at the run time. Based on the result the corresponding Action call or WNR will execute further.

A very simple example as shown below means - Execute the Action call only if it is “Account” session
image

The idea of this post is to explore what else we can use as conditions ? It turned out pretty nice experiment - One can use almost all JS functions. Except the once which are dependent on Browser object (i.e. Window, Navigator, Screen, History and Location).

Let me quickly go with some examples so that you will have some idea on what I’m trying to say over here.

NOTE: All the below example conditions are tested in debugger view and found working fine.

Ex1: Execute Action call only if the Contact’s Country is USA/US/United States/United States Of America
var cntry="[[contact.address1_country]+]".toLowerCase();
cntry=="us" || cntry=="usa"|| cntry=="united states"||cntry=="united states of america"
image
Note the usage of “toLowerCase()” which is a javascript function, basically we are converting the country in lower case first and then comparing it against the possible values.

Ex2: Execute Action call if the First 2 letters of Customer’s post code is “AB” (I know that sounds a crazy requirement Smile)
"[[contact.address1_postalcode]+]".substring(0,2)=="AB"
image
Observe the usage of Substring, which again is a JS function.

In the same way we can use all other string related functions like indexOf, length, search, match, split, trim etc. Its all just your requirement and find out which one would work for you.

Apart from string functions, Date functions also fulfill some nice requirements.

Ex3: Consider a requirement, If the customer is Created before 2010 then open X lob application else open Y lob application. Isn’t it sounding like a valid requirement ? Lets see how we can achieve this with conditions.

Note: As the main concentration is on Conditions in this post, I’m not going to explain how do we create action calls, associate to events etc over here. Refer Neil’s blog where you can find numerous examples on this front.

Create 2 action calls to navigate X & Y Applications. The condition for X application should be
//Condition for X Application

new Date("[[Contact.createdon]+]").getYear()<=2010
image
The condition for Y Application should be
//Condition of Y application

new Date("[[Contact.createdon]+]").getYear()>2010
image
Observe how we have converted the CreatedOn field in to Date and then took the Year part of the date.

Ex4: Lets say the requirement is, If the contact is created in last 30 days then Open “Recently_Created_Contact_Billing_LOB Application”. Not so crazy requirement, Isn’t it ? Lets see how the condition looks like for this.
new Date("[[Contact.createdon]+]") >=new Date().setDate(new Date().getDate()-30)
In the first look it might be looking slightly complex but all we are doing is, removing 30 days from today and forming a new Date which we are comparing against contact created date.

Ex5: One final example. This time with out any replacement parameters and pure javascript methods. Scenario – On the Last Friday of the month, When ever agent opens USD display a message saying “Today is Last Friday, Don’t forget to update Timesheets & Leaves”. If you see here, This is a generic message to user w/o any session/replacement parameters. Lets see the how the condition looks like.
function LastFridayOfMonth() {

var year=new Date().getYear();

var month=new Date().getMonth()+1;    var i, last_day;    i = 0;    while (true) {      last_day = new Date(year, month, i);      if (last_day.getDay() === 5) {        return last_day;      }      i -= 1;    }

};


LastFridayOfMonth().getDate()==new Date().getDate()


image
Well, The condition might be looking like a beast. But the point to note over here is it is not just single line statemetns rather we can even create big functions which does some crazy caluclations as part of our conditions. (ps: the code for LastFridayOfMonth function is found with some random googling, not pretty sure how far it is working correctly – please test once again if you want to use it).

That’s it for now. Hope this post helps in gaining some idea on how we can use Javascript in conditions. You just need to figure out what function would help you and start using !!

HAPPY NEW YEARSmile,  Probably my last post for the year, See you next year Smile

ps: If you find any limitations in using any JS function, it would be nice if you can post it in comments. Helps others also with limitations.


www.CodeNirvana.in

Translate

Total Pageviews

Copyright © CRM Ramblings | Designed By Code Nirvana