Answered by:
crm 4.0 code immigrate to crm 2013

Question
-
Hi all experts,
I am newbie in crm and now we upgrade crm 4.0 to crm 2013. I did not work with crm 4.0 and have very little exprience by crm 2013 (4 Months). I must immigrate Plugin to crm 2013 and there some update code i can't do anything to immigrate 2013.
Can any expert explain or help me what i must do how i must create code?
The code ;
public static Guid createProjekt(int nr) {
Entity projekt=new Entity();
projekt.LogicalName="tqu_projekt";
//test durch nr ersetuzen mit führende nullen
if(nr < 10){
projekt.Attributes["tqu_name"]="P_00000" + nr;
}else if(nr < 100) {
projekt.Attributes["tqu_name"]="P_0000" + nr;
} else if(nr < 1000) {
projekt.Attributes["tqu_name"]="P_000" + nr;
} else if(nr < 10000) {
projekt.Attributes["tqu_name"]="P_00" + nr;
} else if(nr < 100000) {
projekt.Attributes["tqu_name"]="P_0" + nr;
}
projekt.Attributes["tqu_projektnummer"]=new CrmNumber(nr);
TargetCreateDynamic tcd = new TargetCreateDynamic();
CreateRequest cr=new CreateRequest();
tcd.Entity=projekt;
cr.Target=tcd;
CreateResponse r=(CreateResponse)cs.Execute(cr);
Guid g=r.id;
LogicalOperator("Projekt erzeugt");
return g;
}public static void updateEntity(SqlConnection con, CrmService cs, Entity entity) {
try {
TargetUpdateDynamic updateDynamic=new TargetUpdateDynamic();
updateDynamic.Entity=entit;
UpdateRequest update=new UpdateRequest();
update.Target=updateDynamic;
UpdateResponse updated=(UpdateResponse)cs.Execute(update);
}catch(Exception e) {
Log("Create entity failed: " +e.Message;
}
}public static void updateAccount(SqlConnection con, CrmService cs, Entity entity) {
try {
//con.Open
TargetUpdateDynamic updateDynamic=new TargetUpdateDynamic();
updateDynamic.Entity=entit;
UpdateRequest update = new UpdateRequest();
update.Target=updateDynamic;
UpdateResponse updated=(UpdateResponse)cs.Execute(update);
//con.Close();
} catch(Exception e) {
Log("Create entity failed: " +e.Message);
}
}
Thanks a lot who spend time to read this message and going to help me
Sunday, January 25, 2015 1:35 PM
Answers
-
this will be the converted code
public static Guid createProjekt(int nr) { Entity projekt=new Entity("tqu_projekt"); if(nr < 10){ projekt["tqu_name"]="P_00000" + nr; }else if(nr < 100) { projekt["tqu_name"]="P_0000" + nr; } else if(nr < 1000) { projekt["tqu_name"]="P_000" + nr; } else if(nr < 10000) { projekt["tqu_name"]="P_00" + nr; } else if(nr < 100000) { projekt["tqu_name"]="P_0" + nr; } projekt["tqu_projektnummer"]=nr; Guid g = cs.Create(projekt); LogicalOperator("Projekt erzeugt"); // this probably is a custom function return g; } public static void updateEntity(SqlConnection con, CrmService cs, Entity entity) { try { cs.Update(entity); }catch(Exception e) { Log("Create entity failed: " +e.Message; } } public static void updateAccount(SqlConnection con, CrmService cs, Entity entity) { try { cs.Update(entity); }catch(Exception e) { Log("Create entity failed: " +e.Message; } }
However you need first to understand what the code is doing (also if you don't know CRM 4.0 syntax), and after recreate them using CRM 2011/2013 syntax.
As in this case: the code is creating a new record for the entity projekt, you write the same stuff with CRM 2013 syntax
My blog: www.crmanswers.net - Rockstar 365 Profile
- Proposed as answer by Guido PreiteMVP Sunday, January 25, 2015 2:08 PM
- Marked as answer by HIMBAPModerator Saturday, February 14, 2015 3:27 PM
Sunday, January 25, 2015 2:08 PM
All replies
-
this will be the converted code
public static Guid createProjekt(int nr) { Entity projekt=new Entity("tqu_projekt"); if(nr < 10){ projekt["tqu_name"]="P_00000" + nr; }else if(nr < 100) { projekt["tqu_name"]="P_0000" + nr; } else if(nr < 1000) { projekt["tqu_name"]="P_000" + nr; } else if(nr < 10000) { projekt["tqu_name"]="P_00" + nr; } else if(nr < 100000) { projekt["tqu_name"]="P_0" + nr; } projekt["tqu_projektnummer"]=nr; Guid g = cs.Create(projekt); LogicalOperator("Projekt erzeugt"); // this probably is a custom function return g; } public static void updateEntity(SqlConnection con, CrmService cs, Entity entity) { try { cs.Update(entity); }catch(Exception e) { Log("Create entity failed: " +e.Message; } } public static void updateAccount(SqlConnection con, CrmService cs, Entity entity) { try { cs.Update(entity); }catch(Exception e) { Log("Create entity failed: " +e.Message; } }
However you need first to understand what the code is doing (also if you don't know CRM 4.0 syntax), and after recreate them using CRM 2011/2013 syntax.
As in this case: the code is creating a new record for the entity projekt, you write the same stuff with CRM 2013 syntax
My blog: www.crmanswers.net - Rockstar 365 Profile
- Proposed as answer by Guido PreiteMVP Sunday, January 25, 2015 2:08 PM
- Marked as answer by HIMBAPModerator Saturday, February 14, 2015 3:27 PM
Sunday, January 25, 2015 2:08 PM -
Thanks a lot GuidoFriday, March 13, 2015 12:58 PM