Create a balloontip using powershell

BernardJ
Member Posts: 57
Here is an example of using a balloontip to notify the user of something, not important enough to send the user an e-mail, and to avoid an annoying messagebox which have to be clicked away.
In fact, it's only useful in combination with a timer running on every client, to track some changes in certain tables, but i'm not sure if that is a good idea on let's say 30 clients at the same time...
does anybody have experience with this?
In fact, it's only useful in combination with a timer running on every client, to track some changes in certain tables, but i'm not sure if that is a good idea on let's say 30 clients at the same time...
does anybody have experience with this?
OBJECT Codeunit 50000 balloontip { OBJECT-PROPERTIES { Date=28-01-12; Time=14:46:02; Modified=Yes; Version List=; } PROPERTIES { OnRun=BEGIN ShowBalloontip('Notifyicon can show text up to 256 characters', 'Title goes here', 1); END; } CODE { PROCEDURE ShowBalloontip@1000000003(iTxtMessage@1000000003 : Text[256];iTxtTitle@1000000006 : Text[60];iOptTooltipIcon@1000000005 : 'None,Info,Warning,Error'); VAR lFile@1000000000 : File; lAutWshShell@1000000001 : Automation "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 1.0:{72C24DD5-D70A-438B-8A42-98424B88AFB8}:'Windows Script Host Object Model'.WshShell"; lIntWinState@1000000002 : Integer; BEGIN lFile.TEXTMODE := TRUE; lFile.CREATE('c:\temp\message.ps1'); lFile.WRITE('[system.reflection.assembly]::loadwithpartialname("System.Windows.Forms")'); lFile.WRITE('[system.reflection.assembly]::loadwithpartialname("System.Drawing")'); lFile.WRITE('$icon=[system.drawing.icon]::ExtractAssociatedIcon(("'+APPLICATIONPATH+'fin.exe"))'); //Use Powershell-icon instead of NAV's: //lFile.WRITE('$icon=[system.drawing.icon]::ExtractAssociatedIcon((join-path $pshome powershell.exe))'); lFile.WRITE('$notify=new-object system.windows.forms.notifyicon'); lFile.WRITE('$notify.icon=$icon'); lFile.WRITE('$notify.visible=$true'); lFile.WRITE('$notify.balloontiptext="'+iTxtMessage+'"'); lFile.WRITE('$notify.balloontiptitle="'+iTxtTitle+'"'); lFile.WRITE('$notify.balloontipicon=[system.windows.forms.tooltipicon]::'+FORMAT(iOptTooltipIcon)); lFile.WRITE('$notify.showballoontip(10000)'); // get rid of the following two lines if you don't want the tray-icon to disappear after 10 seconds // the icon will disappear however as soon as you mouseover it. lFile.WRITE('sleep(10)'); lFile.WRITE('$notify.dispose()'); lFile.CLOSE; CREATE(lAutWshShell); lIntWinState:=0; // hide window lAutWshShell.Run('powershell.exe -executionPolicy Remotesigned c:\temp\message.ps1',lIntWinState); // you'll need to create a timer if you want to delete the message file // 1 sec of sleep is not sufficient to give powershell enough time //SLEEP(2000); //ERASE('c:\temp\message.ps1'); END; BEGIN END. } }
0
Comments
-
Nice, thanks.
We might use it for notifying the user, when he sends multiple e-mails from Navision.
Sending price lists, reminders etc. to customers. Then after each e-mail a balloontip could show, showing which customer has been e-mailed.
Just like when you get a balloontip when you send a print to the printer queue.
Tip: instead of
lFile.CREATE('c:\temp\message.ps1');
you could use
lFile.CREATE(DELCHR(ENVIRON('TEMP'),'>','\') + '\' + 'NAV_balloontip.ps1');
And instead of deleting the file in function ShowBalloontip you could delete it in CodeUnit 1 in funtion LoginEnd and/or LoginStart.
That's not quite ideal, but works fine for me.
Remember that users can have two Navision-clients open at the same time.
FileRec: Datatype Record, Subtype File.FileRec.RESET; // First filter and search on a different oath, because otherwise Navision would read from the cache. FileRec.SETRANGE(Path, 'C:\'); IF FileRec.FIND('-') THEN ; FileRec.SETRANGE(Path, ENVIRON('TEMP')); FileRec.SETRANGE("Is a file", TRUE); FileRec.SETFILTER(Name, 'Nav_*'); IF FileRec.FIND('-') THEN BEGIN REPEAT IF FileRec.Date <> TODAY THEN IF ERASE(FileRec.Path + '\' + FileRec.Name) THEN ; UNTIL FileRec.NEXT = 0; END;
Keep It Simple and Stupid (KISS), but never oversimplify.0 -
Nobody uses the 'ol ToolTop property anymore? Just us I guess
http://msdn.microsoft.com/en-us/library/dd301088.aspx0 -
fverkel wrote:We might use it for notifying the user, when he sends multiple e-mails from Navision.
Sending price lists, reminders etc. to customers. Then after each e-mail a balloontip could show, showing which customer has been e-mailed.
Just like when you get a balloontip when you send a print to the printer queue.Savatage wrote:Nobody uses the 'ol ToolTop property anymore? Just us I guess0 -
That was a great idea! executing PowerShell scripts from NAV never came to my mind.
Also we can enable clicking on the Balloontip to open NAV with whatever parameters we want.OBJECT Codeunit 50000 balloontip { OBJECT-PROPERTIES { Date=09/26/12; Time=11:51:27 PM; Modified=Yes; Version List=; } PROPERTIES { OnRun=BEGIN ShowBalloontip('Notifyicon can show text up to 256 characters', 'Title goes here', 1); END; } CODE { PROCEDURE ShowBalloontip@1000000003(iTxtMessage@1000000003 : Text[256];iTxtTitle@1000000006 : Text[60];iOptTooltipIcon@1000000005 : 'None,Info,Warning,Error'); VAR lFile@1000000000 : File; lAutWshShell@1000000001 : Automation "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 1.0:{72C24DD5-D70A-438B-8A42-98424B88AFB8}:'Windows Script Host Object Model'.WshShell"; lIntWinState@1000000002 : Integer; BEGIN lFile.TEXTMODE := TRUE; lFile.CREATE('c:\message.ps1'); lFile.WRITE('[system.reflection.assembly]::loadwithpartialname("System.Windows.Forms")'); lFile.WRITE('[system.reflection.assembly]::loadwithpartialname("System.Drawing")'); lFile.WRITE('[system.reflection.assembly]::loadwithpartialname("System.Diagnostics")'); //If already registered, remove lFile.WRITE('Unregister-Event -SourceIdentifier BalloonClicked_event -ea silentlycontinue'); lFile.WRITE('$icon=[system.drawing.icon]::ExtractAssociatedIcon(("'+APPLICATIONPATH+'fin.exe"))'); lFile.WRITE('$notify=new-object system.windows.forms.notifyicon'); lFile.WRITE('$notify.icon=$icon'); lFile.WRITE('$notify.visible=$true'); lFile.WRITE('$notify.balloontiptext="'+iTxtMessage+'"'); lFile.WRITE('$notify.balloontiptitle="'+iTxtTitle+'"'); lFile.WRITE('$notify.balloontipicon=[system.windows.forms.tooltipicon]::'+FORMAT(iOptTooltipIcon)); //we can use this command to open applications upon clicking the Balloontip lFile.WRITE('register-objectevent $notify BalloonTipClicked BalloonClicked_event `'); lFile.WRITE('-Action {[System.Diagnostics.Process]::Start("Finsql")}'); //Also command is there to check if the user Closed the Balloontip lFile.WRITE('$notify.showballoontip(600000)'); lFile.WRITE('sleep(4)'); lFile.WRITE('$notify.dispose()'); lFile.CLOSE; IF ISCLEAR(lAutWshShell) THEN CREATE(lAutWshShell); lIntWinState:=0; // hide window lAutWshShell.Run('powershell.exe -sta -executionPolicy Unrestricted c:\message.ps1',lIntWinState); END; BEGIN END. } }
@fverkel : this can be useful for not only notify the user but also to make him easily open NAV, and I think also we can open a specific form (not sure about that)
notes that i added the -sta parameter, otherwise the BalloonTipClicked event will not work
check this website to see what else you can do :
http://msdn.microsoft.com/en-us/library/9szb3e6y.aspx
Thanks man.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions