Hello Guys I have found the solution to the problem. I have used query by expression. I dont know hwy Query by Attribute did not worked it might be my mistake somewhere but as pf now query By expression is doing my work and I am happy.
here is my code
-------------------------------------
// TODO: Implement your custom Plug-in business logic.
IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "new_testingcrm")
{
try
{
String x = entity.FormattedValues["new_gender"].ToString();
QueryExpression qe = new QueryExpression("prefixcounter");
qe.ColumnSet = new ColumnSet();
EntityCollection SearchContactResult = service.RetrieveMultiple(qe);
//if (SearchContactResult.Entities.Count == 1)
// {
// entity.Attributes["new_medicid"] = SearchContactResult.Entities;
/* if (SearchContactResult.EntityName = "abaxis_prefixcounter")
{
entity.Attributes["new_medicid"] = 1234;
} */
//entity.Attributes["new_medicid"] = SearchContactResult.TotalRecordCount;
Guid counter = new Guid();
foreach (var result in SearchContactResult.Entities)
{
counter = result.Id;
//entity.Attributes["new_callid"] = result.Id.ToString();
// RecordId = result.GetAttributeValue<Guid>("abaxis_prefix1");
}
Entity member = service.Retrieve("abaxis_prefixcounter", counter, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
var prefix1 = member.Attributes["abaxis_prefix1"].ToString();
var prefix2 = member.Attributes["abaxis_prefix2"].ToString();
var medcounter = member.Attributes["abaxis_medcounter"].ToString();
var vetcounter = member.Attributes["abaxis_vetcounter"].ToString();
decimal medcounter2 = Convert.ToDecimal(medcounter);
decimal vetcounter2 = Convert.ToDecimal(vetcounter);
decimal xx = Math.Truncate((medcounter2));
string xy = xx.ToString();
decimal yy = Math.Truncate((vetcounter2));
string yx = yy.ToString();
if (x.Contains("MED"))
{
entity.Attributes["new_callid"] = prefix1 + xy;
member.Attributes["abaxis_medcounter"] = medcounter2 + 1;
}
else
{
entity.Attributes["new_callid"] = prefix2 + yx;
member.Attributes["abaxis_vetcounter"] = vetcounter2 + 1;
}
service.Update(member);
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
-----------------------------------------------------------------------
Thank you guys for the help!!!!