c# - Link Account to activity CRM -


i'm writing code pulls db , populates information activity, i'm able add fields db description , subject field, cant seem link account? here have tried;

foreach (var phonenumber in phonenumbers) {     var potentialmatches = _xrm.accountset.where(account => account.address1_telephone2.equals(phonenumbers)).tolist();      if (potentialmatches.count > 0)     {         var accountmatch = potentialmatches.first();          var actualcrmaccount = (account) _xrm.retrieve("account", accountmatch.id, new microsoft.xrm.sdk.query.columnset(true));          if (actualcrmaccount != null)         {             //is correct way?             new activityparty()             {                 partyid = new entityreference(account.entitylogicalname, actualcrmaccount.id)             };             activityparties.add(new activityparty() {id = actualcrmaccount.id});         }     } } //regardingobjectid not working //regardingobjectid = new entityreference(account.entitylogicalname, recordrow.cells[0].value.tostring); newmsg.to = activityparties; newmsg.description = recordrow.cells[0].value.tostring(); newmsg.subject = recordrow.cells[2].value.tostring();  _xrm.create(newmsg); 

edit 1: when run im getting warning

an unhandled exception of type 'system.servicemodel.faultexception`1' occurred in microsoft.xrm.sdk.dll .
additional information: entity name = 'account' not found in metadatacache.

this piece of code throws warning

var actualcrmaccount = (account)_xrm.retrieve("account", accountmatch.id, new microsoft.xrm.sdk.query.columnset(true)); 

why be?

edit 2: replaced account account, see below.

  var actualcrmaccount = (account)_xrm.retrieve("account", accountmatch.id, new microsoft.xrm.sdk.query.columnset(true)); 

edit 3: im trying leads. when add bit of code.

newmsg.regardingobjectid = activityparties; 

i error.

cannot implicitly convert type 'system.collections.generic.list' 'microsoft.xrm.client.crmentityreference'

how can assign value regardingobjectid.

thanks everyone's help.

the problem you´re adding account via: new activityparty() { id = actualcrmaccount.id }

to define new activityparty must set partyid property entity reference chosen type.

new activityparty() { partyid = new entityreference(account.entitylogicalname,actualcrmaccount.id)    } 

should work.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -