Link to home
Start Free TrialLog in
Avatar of cescentman
cescentmanFlag for United Kingdom of Great Britain and Northern Ireland

asked on

WEBDAV - outlook contact manage custom fields

I am finding it hard to find some information on aspects of WEBDAV and exchange. The next barrier I have come up against is displaying and managing custom fiieds. How to I include these in my select statement?
Avatar of tbsgadi
tbsgadi
Flag of Israel image

Avatar of cescentman

ASKER

Thanks, I have seen both of those articles. I'm struggling to see where custom fields are referred to in the Microsoft article? In either case the articles refer to creating the record I can get this to work. My problem is I can't find any way of selecting and displaying the custom fields on a contact.
I have been trying this since and still drawing a blank, I would be grateful for any help on this.
Avatar of LeeDerbyshire
Can you show the select statement(s) you have tried?  I think custom properties that are not obviously strings have to be CAST as strings in SELECT statements:

http://msdn.microsoft.com/en-us/library/ms879316(EXCHG.65).aspx
Thanks for looking at this.

Just goes to show; all this time I have been searching for help on Custom Fields not Custom Properties. The link was however somewhat inscrutable to me. Having said that what I can be sure of is there is no need to use CAST as all of the Custom Properties I'm interested in are stings.

I don't have any examples of SELECT statements to hand now. What I tried was the code below to list all the properties I could for a record. Then worked my way through removing lines to see if I could work out which part of the XML returned the Custom field records. I drew a blank effectively as I couldn't "reverse engineer" it. My intention is to provide both a listing of the Custom Properties for a record and the ability to search for records containing a string in a Custom Property

I know this shows me up as a dreadful old hacked but there it is!!
$strXMLText = "<a:propfind ";
$strXMLText .= "    xmlns:a='DAV:'";
$strXMLText .= "    xmlns:b='urn:schemas:mailheader:'";
$strXMLText .= "    xmlns:c='urn:schemas:httpmail:'";
$strXMLText .= "    xmlns:d='urn:schemas:contacts:'";
$strXMLText .= "    xmlns:e='urn:schemas:calendar:'";
$strXMLText .= "    xmlns:f='http://schemas.microsoft.com/exchange/'";
$strXMLText .= "    xmlns:g='http://schemas.microsoft.com/mapi/'";
$strXMLText .= "    xmlns:h='http://schemas.microsoft.com/mapi/id/'";
$strXMLText .= "    xmlns:i='http://schemas.microsoft.com/mapi/proptag/'";
$strXMLText .= "    xmlns:j='xml:'";
$strXMLText .= "    xmlns:ee='http://schemas.microsoft.com/exchange/events/'";
$strXMLText .= "    xmlns:es='http://schemas.microsoft.com/exchange/security/'";
$strXMLText .= "    xmlns:ecga='http://schemas.microsoft.com/mapi/id/{00062008-0000-C0000-000000000046}/'";
$strXMLText .= "    xmlns:ft='urn:schemas.microsoft.com:fulltextqueryinfo:'";
$strXMLText .= "    xmlns:ed='urn:schemas-microsoft-com:exch-data:'";
$strXMLText .= "    xmlns:repl='http://schemas.microsoft.com/exchange/events/'";
$strXMLText .= "    xmlns:of='urn:schemas-microsoft-com:office:forms'";
$strXMLText .= "    xmlns:oo='urn:schemas-microsoft-com:office:office'";
$strXMLText .= "    xmlns:uua='urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/'";
$strXMLText .= "    xmlns:xd='urn:schemas-microsoft-com:xml-data' >";
$strXMLText .= "    <a:allprop>";
$strXMLText .= "            <a:allprop />";
$strXMLText .= "            <b:allprop />";
$strXMLText .= "            <c:allprop />";
$strXMLText .= "            <d:allprop />";
$strXMLText .= "            <e:allprop />";
$strXMLText .= "            <f:allprop />";
$strXMLText .= "            <g:allprop />";
$strXMLText .= "            <h:allprop />";
$strXMLText .= "            <i:allprop />";
$strXMLText .= "            <j:allprop />";
$strXMLText .= "            <ee:allprop />";
$strXMLText .= "            <es:allprop />";
$strXMLText .= "            <ecga:allprop />";
$strXMLText .= "            <ft:allprop />";
$strXMLText .= "            <ed:allprop />";
$strXMLText .= "            <repl:allprop />";
$strXMLText .= "            <of:allprop />";
$strXMLText .= "            <oo:allprop />";
$strXMLText .= "            <uua:allprop />";
$strXMLText .= "            <xd:allprop />";
$strXMLText .= "    </a:allprop>";
$strXMLText .= "</a:propfind>";

Open in new window

I'm afraid that ALLPROP doesn't really do what you think it might do.  It just shows the most commonly used properties without you having to list them all.  It won't show you any custom properties at all - you will have to specifically ask for anything that you think might be there.
Well that's why I was using that long piece of XML above. I got it from:-

http://blogs.msdn.com/webdav_101/archive/2008/08/23/santa-i-want-it-all-webdav-and-the-full-meal-deal-allprops.aspx

It does then return custom fields. For example we have a User Defined field "Christmas Cards Sent". Using the above code together with an adaptation of Troy Wolf's HTTP and XML Classes:-

http://www.troywolf.com/articles/php/exchange_webdav_examples.php

I do:-

echo "<pre>";
print_r($objXML->data);
echo "</pre>";

That gives me a vast quantity of properties and amongst them are the Custom Properties including the Christmas Card entry. What I couldn't work out was how to list them selectively and also how to search for them in a WHERE clause. I'm probably on quite the wrong tack.
CHRISTMAS_X0020_CARD_X0020_SENT] => Array
    (
        [0] => stdClass Object
            (
                [_text] => 2006,2008,2009
            )
    )

Open in new window

You will definitely have to supply specific property tags for the WHERE clause - there is no equivalent of ALLPROP that you can use.  Have you used SEARCH yet?  Do you need basic help with that?  Or are you okay using SEARCH, but you just don't know how to add the text for the custom property?
Nope I'm learning on the hoof. So far I haven't tried SEARCH, everything I've managed to do is using SELECT and WHERE clauses. Looked for some accessible Tutorials for WEBDAV. Outlook and Exchange. The problem is that most the documentation I have found is either irrelevant or beyond me so I fall back on my usual technique of learning as I do it. So this has proved to be the most difficult area I have aver chosen!!

As to "supply specific property tags" I was struggling to see how to create the correct tags. As with all things responding to your queries and writing out the problem in detail prompts two pieces of understanding:-

1 the custom tags are stored under their own name attached to the object which I think is:-

DAV:Christmas_X0020_Cards_X0020_Sent

or similar?

2 the mysterious X0020 that has been puzzling me is actual.y a space character, how obvious is that, on moment for a "Dobby the House Elf" moment.

Would I find SEARCH more productive?
ASKER CERTIFIED SOLUTION
Avatar of LeeDerbyshire
LeeDerbyshire
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well I'm getting there. Yes I see what you mean now. I am using DAV:searchrequest, sorry to be so thick.

I have the SELECT working now, I created a Custom Property "Test" to make finding it easy; interestingly the XML was not quite as I imagined, see below. Now to try WHERE.
$objDisplay->xmlrequest = '<?xml version="1.0"?>';
$objDisplay->xmlrequest .= '<q:searchrequest xmlns:q="DAV:">
    <q:sql>
        SELECT "q:href"
            ,"urn:schemas:contacts:fileas"
            ,"urn:schemas:contacts:account"
            ,"urn:schemas:contacts:givenName"
            ,"urn:schemas:contacts:middlename"
            ,"urn:schemas:contacts:sn"
            ,"urn:schemas:contacts:cn"
            ,"urn:schemas:contacts:o"
            ,"urn:schemas:contacts:email1"
            ,"http://schemas.microsoft.com/mapi/email1emailaddress"
            ,"urn:schemas:contacts:telephoneNumber"
            ,"http://schemas.microsoft.com/exchange/keywords-utf8"
            ,"urn:schemas:contacts:street"
            ,"urn:schemas:contacts:l"
            ,"urn:schemas:contacts:st"
            ,"urn:schemas:contacts:postalcode"
            ,"urn:schemas:contacts:co"
            ,"DAV:displayname"
            ,"Test"
        FROM "' . $exchange_server . '/public/' . $strCoContacts . '"
        ' . $strXMLUpdateWhere . '
    </q:sql>
</q:searchrequest>';

Open in new window

Fantastic:-

$strXMLUpdateWhere = 'WHERE "Test" = \'TestingWEBDAV\'';

and bingo.

Thanks, thanks thanks ....
The selected answer is only part of the result. Read the whole thing to be sure you get the whole crux of the solution.

LeeDerbyshire has such patience
Just to clear up one final point. I could not find anyway to SELECT on the Custom Property "Christmas Cards Sent" it shown as "Christmas cards sent" in OutlookSpy. I suspect it is an issue of how to deal with the spaces. Using X0020, %20 or just a space does not work. However in OutllokSpy shows the field having  DASL (DAV Searching and Locating) filter of:-

http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Christmas card sent

Using this as below works.


$objDisplay->xmlrequest = '<?xml version="1.0"?>';
$objDisplay->xmlrequest .= '<q:searchrequest xmlns:q="DAV:">
    <q:sql>
        SELECT "q:href"
            ,"urn:schemas:contacts:fileas"
            ,"urn:schemas:contacts:account"
            ,"urn:schemas:contacts:givenName"
            ,"urn:schemas:contacts:middlename"
            ,"urn:schemas:contacts:sn"
            ,"urn:schemas:contacts:cn"
            ,"urn:schemas:contacts:o"
            ,"urn:schemas:contacts:email1"
            ,"http://schemas.microsoft.com/mapi/email1emailaddress"
            ,"urn:schemas:contacts:telephoneNumber"
            ,"http://schemas.microsoft.com/exchange/keywords-utf8"
            ,"urn:schemas:contacts:street"
            ,"urn:schemas:contacts:l"
            ,"urn:schemas:contacts:st"
            ,"urn:schemas:contacts:postalcode"
            ,"urn:schemas:contacts:co"
            ,"DAV:displayname"
            ,"Test"
            ,"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Christmas card sent"
        FROM "' . $exchange_server . '/public/' . $strCoContacts . '"
        ' . $strXMLUpdateWhere . '
    </q:sql>
</q:searchrequest>';

Open in new window

Sorry for being away - I've just got home from work.  But well done on sorting it out.  Actually, I thought you'd have to use the complete

WHERE "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Test" = 'whatever'

rather than just being able to say

WHERE "Test" = 'whatever'

but if the latter one works, all the better.

if you're wondering where that GUID comes from have a read of this:

http://support.microsoft.com/kb/907985
Thanks for the link, useful reading.