locked
Partylists from custom entity? RRS feed

  • Question

  • Hi all - subject says it all... Is there *any* way I can populate the partylist of a phone call activity from a custom entity? I'm creating the activity from a remote web which uses SOAP to consume the web service, in case that makes any difference...

    I'm still fairly green when it comes to MSCRM (and CRM systems in general) so please go easy on the hardcore terminology, etc ;-)

    Cheers,
     Mattt.
    Tuesday, April 14, 2009 4:18 AM

Answers

  • Hi,

    Sorry, that is not possible.

    You can only get access to the custom entities in the regarding field.

    If you need it in the To/From list, the only way would be to use some of the referenced entities that you are not using, like for instance leads, en rename/reformat it to fit your needs. But can be dangerous; in case you start using leads in the future ....

    I have tested added custom entities using setattribute to fax; it loads all right; but you will see that it fails when you try to save. Some examples below, that I have used in my code.

    if (crmForm.all.to != null) crmForm.all.to.setAttribute("defaulttype","2");
    crmForm.all.to.lookupstyle = 'multi';
    crmForm.all.to.setAttribute("lookuptypes", "2");

    if (crmForm.all.regardingobjectid != null) crmForm.all.regardingobjectid.setAttribute("defaulttype","1");
    crmForm.all.regardingobjectid.setAttribute("lookuptypes", "1,3");



    Morten




    Tuesday, April 14, 2009 11:35 AM

All replies

  • There is a good explenantion on a previous post:

    Morten Dybdahl Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers MedalsTuesday, March 24, 2009 10:59:25 PM
    Has Code
    Hi,

    Thought I could share something similar; here is my code that I used. Feel free to add fields in addition to the phone fields ad company field that I added.

    It's taken out of context; so the functions might not have the naming you want to; but I leave that up to you.

    As you can see I also accumulate companies; since only e-mail addresses where not enough. Check content of that I have comented; marked in red.

    You should also add this in form load, in case To field is set from for instance the contact screen:
    if (crmForm.ObjectId == null)  crmForm.all.to.FireOnChange();

    I entered this code in the to field; change event:

    var xmlConditions = "";
    if (crmForm.all.to.DataValue != null){
    for (i = 0; crmForm.all.to.DataValue[i] != null; i++) {xmlConditions = xmlConditions + "<q1:Value xsi:type='xsd:string'>"+crmForm.all.to.DataValue[i].id+"</q1:Value>" ; }}
    companies(xmlConditions);
    function companies(xmlConditions)
    {
    if (xmlConditions == "") return;
    var authenticationHeader = GenerateAuthenticationHeader();
    var xml = "<?xml version='1.0' encoding='utf-8'?>"+
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
    authenticationHeader+ "<soap:Body>"+ "<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
    "<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'"+
    " xsi:type='q1:QueryExpression'>"+ "<q1:EntityName>contact</q1:EntityName>"+
    "<q1:ColumnSet xsi:type='q1:ColumnSet'>"+ "<q1:Attributes>"+
    "<q1:Attribute>mobilephone</q1:Attribute>"+
    "<q1:Attribute>telephone1</q1:Attribute>"+
    "<q1:Attribute>parentcustomerid</q1:Attribute>"+
    "<q1:Attribute>contactid</q1:Attribute>"+
    "</q1:Attributes>"+ "</q1:ColumnSet>"+
    "<q1:Distinct>false</q1:Distinct>"+ "<q1:Criteria>"+ "<q1:FilterOperator>Or</q1:FilterOperator>"+ "<q1:Conditions>"+ "<q1:Condition>"+
    "<q1:AttributeName>contactid</q1:AttributeName>"+ "<q1:Operator>In</q1:Operator>"+ "<q1:Values>"+ xmlConditions +"</q1:Values>"+
    "</q1:Condition>"+ "</q1:Conditions>"+ "</q1:Criteria>"+ "</query>"+ "</RetrieveMultiple>"+
    "</soap:Body>"+ "</soap:Envelope>";
    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction","
    http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");xHReq.setRequestHeader("Content-Length", xml.length);xHReq.send(xml);
    var resultXml = xHReq.responseXML;
    var errorCount = resultXml.selectNodes('//error').length;
    if (errorCount != 0){ var msg = resultXml.selectSingleNode('//description').nodeTypedValue; alert(msg);}
    else{
     var results = resultXml.getElementsByTagName('BusinessEntity'); var msg = "";
     if (results.length == 0) { return; }
     else
     {
        var companies = ""; var ctrlstring = ""; var mobile = ""; var direct = "";
        for (i=0;i < results.length;i++)
        {
         var name = results[i].xml
         if (name.indexOf("<q1:parentcustomerid name=",0) > 0)
         {

         if (name.indexOf("<q1:mobilephone>",0) > 0 && mobile == "" && direct == "")
        {
             mobile= name.substring(name.indexOf("<q1:mobilephone>",0)+16,999);
             mobile= mobile.substring(0,mobile.indexOf("</q1:mobilephone>",0));
        }

         if (name.indexOf("<q1:telephone1>",0) > 0 && mobile == "" && direct == "")
        {
             direct= name.substring(name.indexOf("<q1:telephone1>",0)+15,999);
             direct = direct.substring(0,direct.indexOf("</q1:telephone1>",0));
        }

         name = name.substring(name.indexOf("<q1:parentcustomerid name=",0),999);
         name = name.substring(name.indexOf("name=",0)+6,999);
         name = name.substring(0,name.indexOf('"',0));
        if (companies == ""){ctrlstring = "#" + name + "#";companies = name;}
        else if (ctrlstring.indexOf("#"+name+"#",0) < 0)
       { companies = companies + ", " + name;
         ctrlstring = ctrlstring + "#" + name + "#"; }
       }}
    //     crmForm.all.new_company.DataValue =  companies.replace("&amp;","&");

       if (mobile + direct != "") crmForm.all.phonenumber.DataValue = mobile + direct;
    }}}


    Tiaan van Niekerk http://crmdelacreme.blogspot.com Skype:tiaan.van.niekerk1
    Tuesday, April 14, 2009 4:37 AM
  • Tiaan,

      Thanks for that, but (and please excuse my ignorance / inexperience) is the code Morten shared only fired when the New Phone Call form is called from the CRM app itself? I need to create instances from a remote web...

      Also, I can't see how it's relevant - but, again, that's probably because I'm still a bit out of my depth here :-)

    Cheers,
     Mattt.
    Tuesday, April 14, 2009 9:58 AM
  • Hi,

    The example referred to is another scenario; i.e. selecting phone/mobile in phone call; which I understand is not what you are asking for.

    You find a more relevant example here that match with your question for how to create phone calls etc. populated with participants here:

    http://crmscape.blogspot.com/2008/10/crm-40-creating-activities.html

    Morten

    from the link you would find this example code:

    var newphoneCall = new phonecall
      {
          ownerid = CrmTypes.CreateOwner(EntityName.systemuser.ToString(), activityOwnerId),
          from = new[]
              {
                  new activityparty
                      {
                          participationtypemask = CrmTypes.CreatePicklist(ActivityPartyType.Sender),
                          partyid = CrmTypes.CreateLookup(EntityName.systemuser.ToString(), activityOwnerId)
                      }
              },
          subject = subject,
          description = description,
          regardingobjectid = (matchedContact) ? CrmTypes.CreateLookup(EntityName.contact.ToString(), relatedContactId) : null,
          to =  (!matchedContact)? null : new []
             {
                new activityparty
                  {
                      participationtypemask = CrmTypes.CreatePicklist(ActivityPartyType.ToRecipient),
                      partyid = CrmTypes.CreateLookup(EntityName.contact.ToString(), relatedContactId)
                  }
             },
          scheduledstart = CrmTypes.CreateCrmDateTime(Convert.ToDateTime(scheduledStart).ToShortDateString()),
          actualstart = CrmTypes.CreateCrmDateTime(Convert.ToDateTime(scheduledStart).ToShortDateString()),
          scheduledend = CrmTypes.CreateCrmDateTime(Convert.ToDateTime(scheduledEnd).ToShortDateString()),
          actualend = (isComplete) ? CrmTypes.CreateCrmDateTime(Convert.ToDateTime(scheduledEnd).ToShortDateString()) : null,
      };

    try
      {
          Guid phonecallId = service.Create(newphoneCall);

          if (isComplete)
          {
              var request = new SetStatePhoneCallRequest
                  {
                      EntityId = phonecallId,
                       PhoneCallState = PhoneCallState.Completed,
                       PhoneCallStatus = 2
                  };

              try
              {
                  service.Execute(request);
              }

              catch (SoapException ex)
              {
                  string errormsg = String.Format("Update Error Setting PhoneCall State to Complete error {0}", ex.Detail.InnerText);
                  WriteErrorFile(errormsg);
              }
          }

      }
    catch (SoapException ex)
       {
           string errormsg = String.Format("Write Error for PhoneCall {0} error {1}", row[(int) tblCal.ACTVCODE], ex.Detail.InnerText);
           WriteErrorFile(errormsg);
       }

    Tuesday, April 14, 2009 11:01 AM
  • Thanks Morten - but what I'm asking about is actually how to include instances of *custom* entities to the party list...

    In this case, my client has a custom entity called 'consumers'. I've been tasked with creating phone call activities from a remote web form which can map consumers to the 'from' or 'to' fields in phone call activity records.

    Cheers,
     Mattt.
    Tuesday, April 14, 2009 11:24 AM
  • Hi,

    Sorry, that is not possible.

    You can only get access to the custom entities in the regarding field.

    If you need it in the To/From list, the only way would be to use some of the referenced entities that you are not using, like for instance leads, en rename/reformat it to fit your needs. But can be dangerous; in case you start using leads in the future ....

    I have tested added custom entities using setattribute to fax; it loads all right; but you will see that it fails when you try to save. Some examples below, that I have used in my code.

    if (crmForm.all.to != null) crmForm.all.to.setAttribute("defaulttype","2");
    crmForm.all.to.lookupstyle = 'multi';
    crmForm.all.to.setAttribute("lookuptypes", "2");

    if (crmForm.all.regardingobjectid != null) crmForm.all.regardingobjectid.setAttribute("defaulttype","1");
    crmForm.all.regardingobjectid.setAttribute("lookuptypes", "1,3");



    Morten




    Tuesday, April 14, 2009 11:35 AM
  • Hi,

    Continued ...

    Probably use the regarding field, populate phone numbers etc.

    Then have some logic in the phone call form in CRM that move around fields a bit; to show the regarding field as the to field; if the related entity in regarding is consumer.

    Morten
    Tuesday, April 14, 2009 11:37 AM