Search code examples
c#dynamics-crm

Set "Regarding" on New Phone Activity In Microsoft Dynamics CRM


I'm trying to open a new phone activity in Microsoft Crm5 by clicking on a button in my windows application. I used Microsoft.xrm.sdk I already can open a new phone activity. I even set the subject and phone number, but I can't set "regardingto look up".

Here is my code:

var extraqs = string.Format("phonenumber={0}&subject={1}{2}", tel1,   HttpUtility.UrlEncode("Calling from "), HttpUtility.UrlEncode(customerName));
extraqs += "&regardingobjectidtype=customer";
extraqs += "&regardingobjectid={" + guid + "}";
extraqs += "&regardingobjectidname=" + customerName;
_url = string.Format("{0}/Activities/phone/edit.aspx?{1}", crmAddress, extraqs);

Process.Start(@"C:\Program Files\Internet Explorer\iexplore.exe", _url);

my regardingto lookup is the list of customers entity. If I remove regardingobjectidtype from parameters, I have no error, but my lookup is not set well. just show the customer name, and form cannot be register. when I add regardingobjectidtype in url parameters, I receive an error and form does not show.


Solution

  • I finally found the answer,

    First of all, I shouldn't use HttpUtility.UrlEncode() I should use Uri.EscapeUriString() for encoding url. Second, I should use pId instead of regardingobjectid and third I should set look up type = 1 not "account".

    Here is the right code:

    var extraqs = string.Format("phonenumber={0}&subject={1}{2}", tel1, "Calling from ", customerName);
    extraqs += "&pType=1";
    extraqs += "&pId={" + guid + "}";
    extraqs += "&pName=";
    
    extraqs += "&partytype=1";
    extraqs += "&partyid={" + guid + "}";
    extraqs += "&partyname=";
    
    _url = string.Format("{0}/Activities/phone/edit.aspx?{1}", crmAddress, Uri.EscapeUriString(extraqs));