Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

unable to update Createdon field??

$
0
0


try
{
var fetch = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='100'>
<entity name='kp_opportunityheader'>
<attribute name='kp_opportunityid' />
<attribute name='kp_opportunity' />
<attribute name='createdon' />
<attribute name='kp_opportunityheaderid' />
<order attribute='createdon' descending='false' />
<link-entity name='opportunity' from='opportunityid' to='kp_opportunity' visible='false' link-type='outer' alias='opp'>
<attribute name='createdon' />
</link-entity>
</entity>
</fetch>";


var fetchExpression = new FetchExpression(fetch);
EntityCollection result = _service.RetrieveMultiple(fetchExpression);
System.IO.StreamWriter file = new System.IO.StreamWriter(@"c:\\Data\\OpportunityHeader.txt");
/

if(result.Entities.Count > 0)
{
foreach (var c in result.Entities)
{

string dateTime = ((Microsoft.Xrm.Sdk.AliasedValue)(c.Attributes["opp.createdon"])).Value.ToString();
DateTime date = Convert.ToDateTime(dateTime);
c.Attributes["createdon"] = ((Microsoft.Xrm.Sdk.AliasedValue)(c.Attributes["opp.createdon"])).Value;
//((Microsoft.Xrm.Sdk.AliasedValue)(c.Attributes["opp.createdon"])).Value;
_service.Update(c);

loops = "Updated OpportunityHeader Guid: " + c.Attributes["kpmg_opportunityheaderid"].ToString() + " Opportunity name: " + ((Microsoft.Xrm.Sdk.EntityReference)(c.Attributes["kpmg_opportunity"])).Name;
Console.WriteLine(loops + "\n");

file.WriteLine(loops);


}
}

/* while (multiResponse.EntityCollection.MoreRecords);*/
file.Close();
Console.WriteLine("Finished");
Console.ReadKey();
}

catch (Exception ex)

{
Console.WriteLine("Error while connecting to CRM " + ex.Message);
Console.ReadKey();
}

}

Above is the highlighted line i am using to update created on date . but unable to do the same. No error. successfully executed , but not getting updated.


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>