Wednesday 5 December 2012

Manipulate Data while importing data to CRM


Hi Folks,
Scenario: When i import excel sheet i have a field in that excel sheet called "employeid" once i import based on that employeeid some record should populate from another entity .
 I have an entity called "Payroll" to which i import data from excel sheet, in that it consists only employeeId. Ther is one more entity called "Employee" which has fields(EmployeeId, CTC).
Now when i import data to "Payroll"entity the CTC should be taken from "Employee"entity based n the employee id and set it in a new field of"Payroll" entity.
Fileds
EmployeeId -text field
CTC - Currency field


Workaround:
Steps:
1)Create a plugin with below code

If (entity.Attributes.Contains("employeeId"))
                {
                    //decimal actualCtc;
                    ConditionExpression condition = new ConditionExpression();
                    condition.AttributeName = "EmployeeId";
                    condition.Operator = ConditionOperator.Equal;
                    condition.Values.Add("employeeId");
                    FilterExpression filter = new FilterExpression();
                    filter.Conditions.Add(condition);

                    QueryExpression query = new QueryExpression("Employee");
                    query.ColumnSet.AddColumns("CTC ");
                    query.Criteria.AddFilter(filter);
                    EntityCollection _queryresult = service.RetrieveMultiple(query);

                    foreach (Entity employeeEntity in _queryresult.Entities)
                    {

                        Money ctc =  (Money)employeeEntity.Attributes["ctc"];
                        actualCtc = ctc.Value;
                    }
                    entity.Attributes["Payroll_CTC"] = new Money(actualCtc);
                    service.Update(entity);
                 
                }

2) Register the Plugin on create message of that entity to which the data is been imported
3)Import Data to CRM
4)Record would be created with CTC fetched from the other entity.

No comments:

Post a Comment