Показать сообщение отдельно
Старый 03.11.2011, 14:06   #1  
u.rastegaev is offline
u.rastegaev
Участник
 
64 / 10 (1) +
Регистрация: 03.08.2010
обнуление полей плагином
Добрый день, а вот такая простая задача, нужно плагином обнулить поля,


TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic();

targetRetrieve.EntityName = "contract";
targetRetrieve.EntityId = contractId;

// Create the request object.
RetrieveRequest retrieve = new RetrieveRequest();


retrieve.Target = targetRetrieve;
retrieve.ColumnSet = new AllColumns();

retrieve.ReturnDynamicEntities = true;

// Execute the request.
RetrieveResponse retrieved = (RetrieveResponse)service.Execute(retrieve);

// Extract the DynamicEntity from the request.
DynamicEntity entity = (DynamicEntity)retrieved.BusinessEntity;








entity.Properties.Remove("gar_state_contract");
entity.Properties.Remove("gar_contracts");
entity.Properties.Remove("title");
entity.Properties.Remove("activeon");

entity.Properties.Remove("gar_date_contract_expiry");
entity.Properties.Remove("gar_date_return_contract");




// Contact PreferredContactMethodCode property
PicklistProperty picklist = new PicklistProperty();
picklist.Name = "gar_state_contract";
picklist.Value = new Picklist();
picklist.Value.Value =1 ;



LookupProperty lkProp = new LookupProperty();
lkProp.Name = "gar_contracts";
lkProp.Value = new Lookup();



StringProperty strProp = new StringProperty();
strProp.Name = "title";
strProp.Value = "";



CrmDateTimeProperty dProp1 = new CrmDateTimeProperty();
dProp1.Name = "activeon";
dProp1.Value = new CrmDateTime(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:s}", "2/24/1955"));



CrmDateTimeProperty dProp2 = new CrmDateTimeProperty();
dProp2.Name = "gar_date_contract_expiry";
dProp2.Value = new CrmDateTime(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:s}", "2/24/1955"));



CrmDateTimeProperty dProp3 = new CrmDateTimeProperty();
dProp3.Name = "gar_date_return_contract";
dProp3.Value = new CrmDateTime(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:s}", "2/24/1955"));







// ArrayList arrProps = new ArrayList();

// Add properties to ArrayList.

entity.Properties.Add(picklist);
entity.Properties.Add(lkProp);
entity.Properties.Add(strProp);
entity.Properties.Add(dProp1);
entity.Properties.Add(dProp2);
entity.Properties.Add(dProp3);

// Update the properties array on the DynamicEntity.
//entity.Properties =
// (Property[])arrProps.ToArray(typeof(Property));

// Create the update target.
TargetUpdateDynamic updateDynamic = new TargetUpdateDynamic();

// Set the properties of the target.
updateDynamic.Entity = entity;

// Create the update request object.
UpdateRequest update = new UpdateRequest();

// Set request properties.
update.Target = updateDynamic;

// Execute the request.

UpdateResponse updated =
(UpdateResponse)service.Execute(update);
__________________
rurik