It's been pretty long since I touched my blog. It's all the new role I took up and crazy work life. Anyways, with the inspiration stolen from Mr. Parkhurst the MVP, the USD "geek" - I will try to be in touch with my readers as much as possible through my posts and comments.
One of the previous projects, the requirement is something like - "Agents should be alerted before closing the session in case of any unsaved changes are there in the Contact/account/Case form they are working on". The OOB behavior of USD is, it will through "Leave/Stay on page" dialog and not even waits for user to respond rather it will simply kills all tabs. Unfortunately, we are not able to find a solution for this problem at that time and so we ended up "masking" the requirement with some generic warning.
In some investigation & reading today, I got this idea which brings the absolute fit solution for this problem. Note that, this is bit of lengthy solution for now - I'm still trying to make it more simpler and will let you all know in a different post if I got succeeded. The good part is, It's a "NO CODE" solution, which many of my friends out there like a lot :)
The solution involves,
a)Create action call for each entity you want to check for changes
b)Attach action call to "session close requested" event
c)Alert user with display message if any unsaved changes found and stop closing session.
Note, For the sake of the blog post, I have considered Account form changes. You need to repeat the same for all other required entities in your project.
So, whenever this event executed it will set the $Return.IsAccountDirty parameter with Yes/No based on the Unsaved changes in the Account form. (FYR, here is a quick screenshot of debugger).
Name : Tell user about Unsaved changes in Account
Hosted Control : CRM Global Manager
Action : Display Message
Data : Hey, Account form has unsaved changes. You can't close the session like this.. :) (Or whatever the message you want to show)
Condition : "[[$Return.IsAccountDirty]+]"=="yes" (Meaning, we want to execute the action call and show the message only if IsAccountDirty is "yes".)
Attach this action call to the same "SessionCloseRequested" event as shown below.
Next, Stopping the Session close. Navigate to action calls, find for the action call named "Close Session". Add a condition to check if the AccountIsDirty which stops the execution of action as shown below.
That’s it, we are done. Open USD, Start a session change something on the account and try to close the session without saving the changes ..
Wolaa.. :)
Hope this helps you guys, All the best !! Please share your thoughts through comments !!
One of the previous projects, the requirement is something like - "Agents should be alerted before closing the session in case of any unsaved changes are there in the Contact/account/Case form they are working on". The OOB behavior of USD is, it will through "Leave/Stay on page" dialog and not even waits for user to respond rather it will simply kills all tabs. Unfortunately, we are not able to find a solution for this problem at that time and so we ended up "masking" the requirement with some generic warning.
In some investigation & reading today, I got this idea which brings the absolute fit solution for this problem. Note that, this is bit of lengthy solution for now - I'm still trying to make it more simpler and will let you all know in a different post if I got succeeded. The good part is, It's a "NO CODE" solution, which many of my friends out there like a lot :)
The solution involves,
a)Create action call for each entity you want to check for changes
b)Attach action call to "session close requested" event
c)Alert user with display message if any unsaved changes found and stop closing session.
Note, For the sake of the blog post, I have considered Account form changes. You need to repeat the same for all other required entities in your project.
- Create Action call to check if the form is Dirty.
function IsAccountDirty() { return Xrm.Page.data.entity.getIsDirty()==true? "yes":"no"; } IsAccountDirty();Note: I don't know if it is a bug or what, but the RunXrmCommand is returning result only if the return value of the command is string. Henceforth, I'm using If condition and returning Yes/No.
- Attach Action call to "SessionCloseRequested" Event.
So, whenever this event executed it will set the $Return.IsAccountDirty parameter with Yes/No based on the Unsaved changes in the Account form. (FYR, here is a quick screenshot of debugger).
- Stop session closing and showing an Alert to user.
Name : Tell user about Unsaved changes in Account
Hosted Control : CRM Global Manager
Action : Display Message
Data : Hey, Account form has unsaved changes. You can't close the session like this.. :) (Or whatever the message you want to show)
Condition : "[[$Return.IsAccountDirty]+]"=="yes" (Meaning, we want to execute the action call and show the message only if IsAccountDirty is "yes".)
Attach this action call to the same "SessionCloseRequested" event as shown below.
Next, Stopping the Session close. Navigate to action calls, find for the action call named "Close Session". Add a condition to check if the AccountIsDirty which stops the execution of action as shown below.
That’s it, we are done. Open USD, Start a session change something on the account and try to close the session without saving the changes ..
Wolaa.. :)
Hope this helps you guys, All the best !! Please share your thoughts through comments !!
4 comments
Great work!!
ReplyNice blog , Very Helpful.
ReplyIf i close it manually, means i clicked x button on session tab, will alert popup stop closing session it after clicking of "Ok" on alert. Doesn't it close after alert closed?
ReplyNo, we are stopping the "Close session" action call with the help of Condition as shown in https://lh3.googleusercontent.com/-AhR9sruvebA/WFGR52_p3uI/AAAAAAAACj4/oETexszgO0Q/s1600-h/6%25255B5%25255D.png
ReplyPost a Comment
Hey, dont forget to leave your name if your giving comment as anonymous user :)