Thanasis Boukouvalas
Posts: 40
Joined: 2006-06-17
|
Hi
I'd like to set the icon of a folder item (e.g. a mail), in order to show to the user that this item is registered to the CRM.
Is there any way to do this? |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Thanasis.
To implement it you will need to customize the Outlook form.
I would advise you to add a new user property to the Outlook item (in the code of the add-in) that has been registered in the CRM. Then you need to customize the folder View to display this property. |
|
Thanasis Boukouvalas
Posts: 40
Joined: 2006-06-17
|
Hi Sergey
I've already use a user property (the CRM registration code) to indicate that item has been registered but I'd prefer to change the original item icon because I cannot find how I can change the folder View programmatically.
So,
1. is there any way to change the "original" item icon or
2. if I use a second user property as "my" icon, is there a way to change the folder view programmatically (I suppose the second is more difficult) |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Thanasis.
In this situation the first is more difficult. You will face difficulties with the add-in deployment since you will have to change the outlook form in the code of the add-in.
I would suggest you to create a new View for a folder using the Views collection of the Outlook folder (see the 'Views Collection' chapter in the Microsoft Visual Basic Help). You can create a new view based on the current view. In this case you will need to obtain the XML property of the folder and change the XML schema a little.
I have the example code. I used to implement this algorithm for incoming emails. This is the Delphi code. I hopy you will manage to understand it.
procedure TDWMWMainForm.NewMessage(var Message: TMessage);
const
olTableView = $00000000;
olCardView = $00000001;
olCalendarView = $00000002;
olIconView = $00000003;
olTimelineView = $00000004;
olViewSaveOptionThisFolderEveryone = $00000000;
olViewSaveOptionThisFolderOnlyMe = $00000001;
olViewSaveOptionAllFoldersOfType = $00000002;
var
NamedPropertyRec: NamedPropertyRecord;
Msg: TRwMapiMessage;
MsgId : TRwEntryId;
FolderId : TRwEntryId;
StrMsgId: PChar;
PropertyTag: Cardinal;
TaskID, SAPFolderName: string;
DWMailID: string;
Inbox: TRwMapiFolder;
TaskFolder: TRwMapiFolder;
OlRootFolder: OleVariant;
OlTaskFolder: OleVariant;
ViewExists: Boolean;
OlViews: OleVariant;
OlView: OleVariant;
OlMailItem: OleVariant;
XmlString, DWColumns: string;
i, p, n: Integer;
Headers: TStringList;
//Text: TStringList;
ExprLabel, s: String;
NewMsgID: String;
OlExplorer: OleVariant;
PropItem: TRwMapiPropItem;
Number: Integer;
begin
try
n := 0; Number := -1;
WriteToLog('Inside of NewMessage procedure.');
StrMsgId := PChar(Message.WParam);
try
MsgId := StringToRwEntryID(string(StrMsgId));
finally
StrDispose(StrMsgId);
end;
WriteToLog('The message ID is ' + StrMsgId);
Msg := MsgStore.OpenMessage(MsgId, alBestAccess);
try
WriteToLog('Getting the WorkItemID property...');
PropItem := Msg.NamedPropByID(gc_DWTaskID, DWMailID_GUIID, False, PT_STRING8);
if (PropItem <> nil) then begin
WriteToLog('Getting the TaskID property...');
TaskID := Trim(PropItem.AsString); //.NamedPropByID(gc_DWTaskID, DWMailID_GUIID, False, PT_STRING8).AsString;
if TaskID <> '' then begin
WriteToLog('Processing the ' + TaskID + ' property (TaskID).');
DWMailID := Msg.NamedPropByID(gc_DWMailID, DWMailID_GUIID, False, PT_STRING8).AsString;
Inbox := MsgStore.OpenFolder(Msg.FolderID, alBestAccess);
WriteToLog('Creating the ' + TaskID + ' folder.');
SAPFolderName := Msg.NamedPropByID(gc_DWTaskTextID, DWMailID_GUIID, False, PT_STRING8).AsString;
if SAPFolderName = '' then
SAPFolderName := TaskID;
TaskFolder := FindFolder(Inbox, SAPFolderName, TaskID, Number);
if TaskFolder = nil then begin
if Number >= 0 then
SAPFolderName := SAPFolderName + ' ' + IntToStr(Number + 1);
TaskFolder := Inbox.CreateFolder(SAPFolderName, 'Desktop Workplace work items (Task ID = ' + TaskID + ').', True);
end;
WriteToLog('Moving the ' + TaskID + ' folder.');
Inbox.MoveMessage(MsgId, TaskFolder);
NamedPropertyRec.PropertyID := gc_DWMailID;
NamedPropertyRec.GUIID := DWMailID_GUIID;
NamedPropertyRec.Value := DWMailID;
WriteToLog('Finding a new email in the ' + TaskID + ' folder.');
NewMsgID := FindMail(NamedPropertyRec, TaskFolder.FolderId);
OlMailItem := Namespace.GetItemFromID(NewMsgID, RwEntryIDToOutlookID(Msg.MessageStoreID));
WriteToLog('The email has been found. Adding user properties...');
for i:=1 to 6 do begin
PropertyTag := Msg.CreateNamedProperty(gc_DWCustomID + IntToStr(i), DWMailID_GUIID, PT_STRING8);
if (Msg.HasProp(PropertyTag)) then begin
ExprLabel := Msg.NamedPropByID(gc_DWCustomID + IntToStr(i), DWMailID_GUIID, False, PT_STRING8).AsString;
OlMailItem.UserProperties.Add('EXPRLABEL' + IntToStr(i), 1, True);
OlMailItem.UserProperties.Item('EXPRLABEL' + IntToStr(i)) := ExprLabel;
OlMailItem.Save;
WriteToLog('The EXPRLABEL' + IntToStr(i) + ' property has just been added.');
end;
end;
WriteToLog('Finding the ' + TaskID + ' folder.');
OlTaskFolder := Namespace.GetFolderFromID(RwEntryIDToOutlookID(TaskFolder.FolderId), RwEntryIDToOutlookID(Msg.MessageStoreID));
OlViews := OlTaskFolder.Views;
WriteToLog('The folder has been found. Finding the DWView...');
ViewExists := False;
for i := 1 to OlViews.Count do
if OlViews.Item(i).Name = 'DWView' then begin
ViewExists := True;
OlView := OlViews.Item(i);
{Text := TStringList.Create;
Text.Text := OlView.XML;
Text.SaveToFile('D:\view.xml');
Text.Free;}
WriteToLog('The DWView view has been found.');
Break;
end;
if not ViewExists then begin
WriteToLog('The DWView view hasn''t been found. Adding a new view...');
OlView := OlViews.Add('DWView', olTableView, olViewSaveOptionThisFolderEveryone);
XmlString := OlView.XML;
WriteToLog('The original view is ' + XmlString);
WriteToLog('Getting the <orderby> tag position...');
p := Pos('<orderby>', XmlString);
if p > 0 then begin
DWColumns := '';
try
WriteToLog('The position is ' + IntToStr(p));
WriteToLog('Getting headers from SAP...');
Headers := GetHeaders(DWMailID, TaskID);
if Headers.Count > 0 then begin
for i:= 0 to Headers.Count - 1 do begin
DWColumns := DWColumns + #$D#$A#9 + '<column>';
WriteToLog('Processing the ''' + Headers[i] + ''' header.');
DWColumns := DWColumns + #$D#$A#9#9 + '<heading>' + Headers[i] + '</heading>';
DWColumns := DWColumns + #$D#$A#9#9 + '<prop>http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/EXPRLABEL' + IntToStr(i+1) + '</prop>';
DWColumns := DWColumns + #$D#$A#9#9 + '<type>string</type>';
DWColumns := DWColumns + #$D#$A#9#9 + '<width>22</width>';
DWColumns := DWColumns + #$D#$A#9#9 + '<style>padding-left:3px;;text-align:left</style>';
DWColumns := DWColumns + #$D#$A#9#9 + '<userheading>' + Headers[i] + '</userheading>';
DWColumns := DWColumns + #$D#$A#9 + '</column>';
end;
end;
if DWColumns <> '' then begin
DWColumns := DWColumns + #$D#$A#9;
Insert(DWColumns, XmlString, p);
end;
finally
Headers.Free;
end;
end;
WriteToLog('The new view is ' + XmlString);
OlView.XML := XmlString;
OlView.Save;
WriteToLog('The new is saved.');
try
OlView.Apply;
except
// For some reason Outlook raises an exeception when it is run in the background,
// but the DW view is applied successfully.
end;
WriteToLog('The new is applied.');
end;
end;
end;
finally
WriteToLog('Exit.');
OlExplorer := Unassigned;
OlView := Unassigned;
OlViews := Unassigned;
OlMailItem := Unassigned;
OlTaskFolder := Unassigned;
OlRootFolder := Unassigned;
//if PropItem <> nil then
// PropItem.Free;
if TaskFolder <> nil then
TaskFolder.Free;
if Inbox <> nil then
Inbox.Free;
if Msg <> nil then
Msg.Free;
end;
except
on e: SysUtils.Exception do begin
//ShowDWMsg('Desktop Workplace Mail Watcher error', e.Message, mtError, False);
WriteToLog('Error: ' + e.Message);
end;
end;
end;
|
|
Thanasis Boukouvalas
Posts: 40
Joined: 2006-06-17
|
Hi Sergey and thank you very very very much.
I didnt known that I could create programmatically a folder view with XML.
Now I can have a view based on the current view with one more column.
Do you known if I can show an icon (rather that text) like attachment column does?
I cannot find any documentation about how a boolicon column can set the icon
MyColumn:
<column>
<format>boolicon</format>
<heading>Registered at Entersoft CRM</heading>
<prop>http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/ESCRMRegistered</prop>
<type>boolean</type>
<width>30</width>
<style>padding-left:3px;;text-align:center</style>
<displayformat>3</displayformat>
<userheading>ESCRM</userheading>
</column>
Attachment column:
<column>
<format>boolicon</format>
<heading>Attachment</heading>
<prop>urn:schemas:httpmail:hasattachment</prop>
<type>boolean</type>
<bitmap>1</bitmap>
<width>10</width>
<style>padding-left:3px;;text-align:center</style>
<displayformat>3</displayformat>
</column>
|
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Thanasis.
The fact is that the Outlook.OlUserPropertyType enumeration doesn't contain the Icon property type. But you can use the Yes/No type instead.
You can read more about the Add method of the UserProperties interface in the Microsoft Visual Basic Help in Outlook.
|
|