use linq method wcf ria - silverlight

i have this method in my domainService
public IQueryable Getbl()
{
var qer = from t in this.ObjectContext.lignes_bl
from t0 in this.ObjectContext.entete_bl
where
t.NO_BL == t0.NO_BL
orderby
t.NO_BL,
t.NO_LIGNE
select new
{
IDentete_bl = t0.IDENTETE_BL,
NO_BL = t0.NO_BL,
DATE_BL = t0.DATE_BL,
FAC_AVOIR = t0.FAC_AVOIR,
REF_BL = t0.REF_BL,
CODE_CLIENT = t0.CODE_CLIENT,
NOM_CLIENT = t0.NOM_CLIENT,
ADRESSE = t0.ADRESSE,
CODE_PAYS = t0.CODE_PAYS,
VILLE = t0.VILLE,
CODE_POSTAL = t0.CODE_POSTAL,
ZONE = t0.ZONE,
TEL_FAX = t0.TEL_FAX,
CODE_ADL = t0.CODE_ADL,
NOM_ADL = t0.NOM_ADL,
ADRESSE_ADL = t0.ADRESSE_ADL,
CODE_POSTAL_ADL = t0.CODE_POSTAL_ADL,
VILLE_ADL = t0.VILLE_ADL,
MT_TTC_BL = t0.MT_TTC_BL,
CODE_PAYS_ADL = t0.CODE_PAYS_ADL,
TEL_FAX_ADL = t0.TEL_FAX_ADL,
REM = t0.REM,
CODE_REGLEMENT = t0.CODE_REGLEMENT,
NO_FACTURE = t0.NO_FACTURE,
DATE_FACTURE = t0.DATE_FACTURE,
CODE_COMPTA = t0.CODE_COMPTA,
SITE = t0.SITE,
CODE_COMMERCIAL = t0.CODE_COMMERCIAL,
NBR_COLIS = t0.NBR_COLIS,
NOM_TRANSPORTEUR = t0.NOM_TRANSPORTEUR,
FACTURE_DIRECTE = t0.FACTURE_DIRECTE,
MOIS_FACTURE = t0.MOIS_FACTURE,
CLE_SITE_MOIS_FAC = t0.CLE_SITE_MOIS_FAC,
CLE_SITE_FD_CC = t0.CLE_SITE_FD_CC,
CLE_SITE_FD = t0.CLE_SITE_FD,
CLE_SITE_FD_CC_EDIT = t0.CLE_SITE_FD_CC_EDIT,
ARCHIVAGE = t0.ARCHIVAGE,
NO_TVA_CL = t0.NO_TVA_CL,
numero = t0.numero,
Bis = t0.bis,
voie = t0.voie,
P_identite = t0.P_identite,
p_numero = t0.p_numero,
p_du = t0.p_du,
p_par = t0.p_par,
nais_du = t0.nais_du,
nais_ville = t0.nais_ville,
nais_dep = t0.nais_dep,
nais_pays = t0.nais_pays,
num_siren = t0.num_siren,
id_bon_ademe = t0.id_bon_ademe,
poids_ademe_vhu = t0.poids_ademe_vhu,
CODE_BROYEUR = t0.CODE_BROYEUR,
IDlignes_bl = t.IDLIGNES_BL,
CODE_CLIENT_LI = t.CODE_CLIENT,
NO_BL_LI = t.NO_BL,
DATE_BL_LI = t.DATE_BL,
FAC_AVOIR_LI = t.FAC_AVOIR,
CODE_ARTICLE = t.CODE_ARTICLE,
NO_VEHICULE = t.NO_VEHICULE,
DESIGNATION = t.DESIGNATION,
QTE = t.QTE,
PU_HT = t.PU_HT,
REM_LI = t.REM,
CODE_TVA = t.CODE_TVA,
TAUX_TVA = t.TAUX_TVA,
NO_LIGNE = t.NO_LIGNE,
TYPE_ARTICLE = t.TYPE_ARTICLE,
LIB_LIBRE = t.LIB_LIBRE,
DESI_ARTICLE = t.DESI_ARTICLE,
CODE_GARANTIE = t.CODE_GARANTIE,
NO_FACTURE_LI = t.NO_FACTURE,
CODE_REGLEMENT_LI = t.CODE_REGLEMENT,
SITE_LI = t.SITE,
LIB_MODELE = t.LIB_MODELE,
PA_HT_TTC = t.PA_HT_TTC,
PU_NET = t.PU_NET,
PU_TTC = t.PU_TTC,
code_id_article = t.code_id_article,
site_stockage = t.site_stockage,
sans_trait_haut = t.sans_trait_haut,
nom_article_unique_demonter = t.nom_article_unique_demonter,
code_ademe_ligne = t.code_ademe_ligne,
poids_ademe = t.poids_ademe,
type_article_ademe = t.type_article_ademe,
consistance = t.consistance,
conditionnement = t.conditionnement,
nombre_carcasse = t.nombre_carcasse,
num_vehicule_entretien = t.num_vehicule_entretien,
num_immat_vehi_entretien = t.num_immat_vehi_entretien
};
return qer.AsQueryable();
and i have this code in button ,the problem is does not contain a definition for Getbl ?
DomainService1 testContext = new DomainService1();
private void button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
InitializeComponent();
var res = testContext.Getbl();
}

Getbl returns an enumeration of an anonymous type. Anonymous types have only internal accessibility hence getbl is not included in service since that would in effect mean it would have return a list of type instances that should not be exposed publically.
Create a public class the has the list of Properties you want to return and include a new instance of this public class in your Select projection rather than using an anonymous type.

in addition to AnthonyWJones answer:
Use LoadOperation to get the data from the server:
LoadOperation<Customer> loadOp = this._customerContext.Load(this._customerContext.GetCustomersQuery());
CustomerGrid.ItemsSource = loadOp.Entities;
Note: Your method will have an appendix "Query" which RIA adds to Query methods.

Related

Test class coverage not increasing after 71 %. "Bold Italic part is not covering in Test class."

enter image description hereThe trigger is working completely fine, but Its not giving 100% code coverage. The main issue with Test class, its not covering the if condition of Role__c.
Trigger:
trigger DrawingSharing on Drawing__c (after insert) {
if(trigger.isInsert){
for (Drawing__c draw : Trigger.new){
System.debug('draw: '+draw);
List<Installation__c> ListInstalltionList = new List <Installation__c>();
for(String installationActivityList :draw.Installation_Activity__c.split(';')){
Installation__c inst = new Installation__c();
inst.Drawing_ID__c = draw.Id;
inst.Installation_Activity__c=installationActivityList;
inst.Execution__c=draw.Execution_ID__c;
inst.Floor__c=draw.Floors__c;
ListInstalltionList.add(inst);
}
system.debug('ListInstalltionList==>'+ListInstalltionList);
insert ListInstalltionList;
List<Drawing__c> newList = new List<Drawing__c>();
newList.add(draw);
Map <Id,Id> DrawingProjectMap = new Map<Id,Id>();
Map<Id,Drawing__c> drawingIdObjMap = new Map<Id,Drawing__c>([select id, name,Approver__c, Execution_ID__r.Project__c from Drawing__c where id in :newList limit 1]);
for(Drawing__c Drawing : drawingIdObjMap.values())
{
DrawingProjectMap.put(Drawing.Id,Drawing.Execution_ID__r.Project__c);
}
system.debug(DrawingProjectMap);
Map<Id,RoleObjectSharing__mdt> roleobjaccessmap = new Map<Id,RoleObjectSharing__mdt>([select id,Object__c,role__c,Accesslevel__c from RoleObjectSharing__mdt where Object__c='Drawing']);
Map<String,String> RoleAccessmap = new Map<String,String>();
for(RoleObjectSharing__mdt Robj : roleobjaccessmap.values()){
RoleAccessmap.put(Robj.role__c,Robj.Accesslevel__c);
}
system.debug(RoleAccessmap.keySet());
system.debug(DrawingProjectMap.values());
Map<Id,Projects__c> teamrolemap = new Map<Id,Projects__c>([select Id,(select id, User_Lookup__c,Role__c from TeamRoles__r where Role__c in:RoleAccessmap.keySet()) from Projects__c where Id in :DrawingProjectMap.values()]);
system.debug('teamrolemap'+teamrolemap);
List <Drawing__Share> DrawShareList = new List<Drawing__Share>();
List <Drawing__c> DrawList = new List<Drawing__c>();
INTEGER countFound = 0;
for(Drawing__c drawobj : newList){
Projects__c proj = teamrolemap.get(DrawingProjectMap.get(drawobj.id));
system.debug(proj.teamroles__r);
***for(teamroles__c tr : proj.teamroles__r){
system.debug(tr);
if(tr.Role__c == 'PlanningEngineer' || tr.Role__c == 'AssistantPlanningEngineer' || tr.Role__c == 'PlanningManager' || tr.Role__c == 'AssistantPlanningManager' && countFound <=0) {
countFound = countFound + 1;
Drawing__c ddd = drawingIdObjMap.values();
ddd.Approver__c = tr.User_Lookup__c;
DrawList.add(ddd);
}
Drawing__Share recruiterShr = new Drawing__Share();
recruiterShr.ParentId = drawobj.Id;
recruiterShr.UserOrGroupId = tr.User_Lookup__c;
recruiterShr.AccessLevel = RoleAccessmap.get(tr.role__c);
recruiterShr.RowCause = tr.role__c+'__c';
DrawShareList.add(recruiterShr);***
}
system.debug(DrawShareList);
}
upsert DrawList;
Database.SaveResult[] lsr = Database.insert(DrawShareList,false);
Integer i=0;
for(Database.SaveResult sr : lsr){
if(!sr.isSuccess()){
}
i++;
}
}
}
}
Test Class:
static testMethod void Test4(){
System.debug('TestSharing = Test4');
Test.startTest();
Projects__c proj = new Projects__c();
proj.Name = 'Hello';
proj.LL_Location__c='Mumbai';
insert proj;
TeamRoles__c tr1 = new TeamRoles__c();
tr1.User_Lookup__c = UserInfo.getUserId();
tr1.Role__c = 'PlanningEngineer';
tr1.Project_Name__c = proj.Id;
insert tr1;
TeamRoles__c tr2 = new TeamRoles__c();
tr2.User_Lookup__c = UserInfo.getUserId();
tr2.Role__c = 'PlanningManager';
tr2.Project_Name__c = proj.Id;
insert tr2;
Execution__c ex = new Execution__c();
ex.Project__c = proj.Id;
insert ex;
Item_Master__c ItemeMaster = new Item_Master__c();
ItemeMaster.Item_Description__c = 'testing';
ItemeMaster.Item_Code__c = 'testing';
insert ItemeMaster;
Project_Items__c projItems = new Project_Items__c();
projItems.Total_PO_Quantity__c = 0;
projItems.ItemMaster__c = ItemeMaster.Id;
projItems.Execution__c = ex.Id;
insert projItems;
List<TeamRoles__c> lstTR = new List<TeamRoles__c>();
TeamRoles__c tr7 = new TeamRoles__c();
tr7.User_Lookup__c = UserInfo.getUserId();
tr7.Role__c = 'PlanningEngineer';
tr7.Project_Name__c = proj.Id;
lstTR.add(tr7);
List<Drawing__c> d= new List<Drawing__c>();
Drawing__c draw = new Drawing__c();
draw.Execution_Id__c = ex.Id;
draw.Floors__c='5F';
draw.Installation_Activity__c='Cable Tray';
draw.Drawing_Line_Items_Count__c = 0;
d.add(draw);
insert d;
//insert draw;
Installation__c inst = new Installation__c();
inst.Drawing_ID__c=draw.Id;
inst.Floor__c= draw.Floors__c;
inst.Installation_Activity__c='Cable Tray';
inst.As_built_Marked_Drawing_Prepared_by_Site__c =False;
inst.Execution__c = ex.Id;
insert inst;
SharingUtilityClass suc = new SharingUtilityClass();
suc.initObjSharing(lstTR);
Drawing_Line_Items__c dll = new Drawing_Line_Items__c();
dll.Drawing_Number__c = draw.Id;
dll.Project_Items__c = projItems.Id;
dll.Project_Name__c = proj.Id;
dll.Installation_Activity__c='Cable Tray';
dll.GFC_Quantity__c = 15;
dll.Shop_Drawing_Quantity__c = 20;
dll.GFC_Drawing_Line_Item_Done__c = true;
dll.Shop_Drawing_Line_Item_Done__c=true;
insert dll;
Installation_Line_Items__c instline = new Installation_Line_Items__c();
instline.Installation__c = inst.Id;
instline.Project_Items__c = projItems.Id;
instline.Installation_Activity__c='Cable Tray';
instline.Total_installed_quantity_DPR_Quantity__c = 100.00;
insert instline;
List<Drawing_Line_Items__c> listProj2 = CircularProgressController.getDrawingLineItem(dll.Id);
List<Drawing_Line_Items__c> listProj3 = CircularProgressController.getDrawingLineItemShop(dll.Id);
List<Drawing__c> listProj4 = Drawing.getDrawing(draw.Id);
List<Project_Items__c> listProj5 = Drawing.getProjectItems(ex.Id);
Test.stopTest();
}
If there are team roles being debugged from this line
for(teamroles__c tr : proj.teamroles__r){
system.debug(tr);
I would then check to see if this is evaluating to true within the test context:
if(tr.Role__c == 'PlanningEngineer' || tr.Role__c == 'AssistantPlanningEngineer' || tr.Role__c == 'PlanningManager' || tr.Role__c == 'AssistantPlanningManager' && countFound <=0)

Not able to update the data in more than one table in Asp .net MVC5

Here I am able to add the data in more than one table. Let i have 3 tables User, Franchise and Fee.
I am not able to update the data in more than one table,it throwing the exception:
A referential integrity constraint violation occurred: The property value(s) of 'User.Id' on one end of a relationship do not match the property value(s) of 'Franchise.UserId' on the other end.
Code:
public MessageResult SaveAndUpdateFranchisee(UserViewModel model)
{
var result = new MessageResult();
try
{
User userData = new User();
Franchise franchiseData = new Franchise();
var ExistUser = db.Users.Where(a => a.Id == model.Id).FirstOrDefault();
//Update record
if (model.Id > 0)
{
Fee feeData = new Fee
{
FranchiseeFee = model.FranchiseeFee,
PaymentTermsFranchiseFee = model.PaymentTermsFranchiseFee,
EquipmentCost = model.EquipmentCost,
PaymentTermsEquipmentCost = model.PaymentTermsEquipmentCost,
OtherFee = model.OtherFee,
PaymentTermsOtherFee = model.PaymentTermsOtherFee,
ConsumableStock = model.ConsumableStock,
PaymentTermsConsumableStock = model.PaymentTermsConsumableStock,
FrozenFoodStock = model.FrozenFoodStock,
PaymentTermsFrozenFoodStock = model.PaymentTermsFrozenFoodStock,
TotalAmountDue = model.TotalAmountDue,
TotalAmountPaid = model.TotalAmountPaid,
BalanceAmount = model.BalanceAmount,
LoyaltyFeePercentage = model.LoyaltyFeePercentage,
FixedMonthlyFee = model.FixedMonthlyFee,
Note = model.Note,
UserId = model.CurrentUserId,
LOIDocUrl = model.LOIDocUrl,
ModifiedDate = DateTime.Now
};
ExistUser.Email = model.Email;
//var pwd = SecutiryServices.EncodePasswordToBase64(model.Password);
//userData.Password = pwd;
ExistUser.Password = model.Password;
ExistUser.FirstName = model.FirstName;
ExistUser.MiddleName = model.MiddleName;
ExistUser.LastName = model.LastName;
ExistUser.FullName = model.FullName;
ExistUser.MobileNo = model.MobileNo;
ExistUser.ModifyDate = DateTime.Now;
franchiseData.Name = model.FullName;
franchiseData.MobileNo = model.MobileNo;
franchiseData.AlternateNo = model.AlternetNo;
franchiseData.CompanyPhoneNo = model.PhoneNo;
franchiseData.Address = model.Address;
franchiseData.City = model.City;
franchiseData.State = model.State;
franchiseData.PinCode = model.PinCode;
franchiseData.CompanyName = model.CompanyName;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyCity = model.CompanyCity;
franchiseData.CompanyState = model.CompanyState;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyPinCode = model.CompanyPinCode;
franchiseData.ModifiedDate = DateTime.Now;
userData.Franchises.Add(franchiseData);
foreach (var item in userData.Franchises)
{
item.Fees.Add(feeData);
}
db.Users.Attach(userData);
db.Entry(userData).State = System.Data.Entity.EntityState.Modified;
//db.Users.Add(userData);
db.SaveChanges();
result.Message = "Your franchise has been updated successfully..";
result.Status = true;
}
//For Insert recored..
else
{
Fee feeData = new Fee
{
FranchiseeFee = model.FranchiseeFee,
PaymentTermsFranchiseFee = model.PaymentTermsFranchiseFee,
EquipmentCost = model.EquipmentCost,
PaymentTermsEquipmentCost = model.PaymentTermsEquipmentCost,
OtherFee = model.OtherFee,
PaymentTermsOtherFee = model.PaymentTermsOtherFee,
ConsumableStock = model.ConsumableStock,
PaymentTermsConsumableStock = model.PaymentTermsConsumableStock,
FrozenFoodStock = model.FrozenFoodStock,
PaymentTermsFrozenFoodStock = model.PaymentTermsFrozenFoodStock,
TotalAmountDue = model.TotalAmountDue,
TotalAmountPaid = model.TotalAmountPaid,
BalanceAmount = model.BalanceAmount,
LoyaltyFeePercentage = model.LoyaltyFeePercentage,
FixedMonthlyFee = model.FixedMonthlyFee,
Note = model.Note,
UserId = model.CurrentUserId,
LOIDocUrl = model.LOIDocUrl,
CreatedDate = DateTime.Now
};
userData.Email = model.Email;
//var pwd = SecutiryServices.EncodePasswordToBase64(model.Password);
//userData.Password = pwd;
userData.Password = model.Password;
userData.FirstName = model.FirstName;
userData.FullName = model.FirstName + " " + model.LastName;
userData.LastName = model.LastName;
userData.MobileNo = model.MobileNo;
userData.IsActive = true;
userData.IsDelete = false;
userData.CreatedDate = DateTime.Now;
userData.UserTypeId = 2;
franchiseData.CompanyId = model.CurrentUserId;
franchiseData.Name = userData.FullName;
franchiseData.MobileNo = model.MobileNo;
franchiseData.AlternateNo = model.AlternetNo;
franchiseData.Address = model.Address;
franchiseData.City = model.City;
franchiseData.State = model.State;
franchiseData.PinCode = model.PinCode;
franchiseData.CompanyName = model.CompanyName;
franchiseData.CompanyPhoneNo = model.PhoneNo;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyCity = model.CompanyCity;
franchiseData.CompanyState = model.CompanyState;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyPinCode = model.CompanyPinCode;
franchiseData.CreatedDate = DateTime.Now;
franchiseData.IsActive = true;
userData.Franchises.Add(franchiseData);
foreach (var item in userData.Franchises)
{
item.Fees.Add(feeData);
}
db.Users.Add(userData);
db.SaveChanges();
//db.AddUserRole(userData.Id, 4);
result.Message = "Your franchisee has been created successfully..";
result.Status = true;
}
return result;
}
catch (Exception ex)
{
result.Message = "We are unable to process your request at this time. Please try again later.";
result.Status = false;
return result;
}
}
The error message is straightforward - your code is creating a new Franchise object but it never sets the franchiseData.UserId property.
Add this to your franchiseData population code before you call db.SaveChanges():
franchiseData.UserId = model.CurrentUserId;
BTW, you should add code verify that the current user has permission to set foreign-key reference properties (like UserId) directly from values read from submitted forms because otherwise any user could enter Id values belonging to other users and gain access to information they shouldn't have access to - or otherwise alter with your database.

Unable to add more entries to Firebase after 11

I have a database in firebase that is meant to hold user data and I'm able to get it to add account data up to number 10 (zero based), but after that, anytime I call the function to add to the database it doesn't show up in Firebase. I am using this for a game in Unity. Here are the function calls.
`
public void populateDatabase()
{
//populate static account data
AccountData _thisAccount = new AccountData();
_thisAccount.accName = Account.instance.NickName();
_thisAccount.accEmail = PlayerAccount._this.getUserEmail();
_thisAccount.accCash = 100;
_thisAccount.accGem = 100;
//Ranking Values
_thisAccount.Rank = 0;
//rookie
_thisAccount.RookieRank = 0;
_thisAccount.RookieAverage = 0;
_thisAccount.RookieScoreOne = 0;
_thisAccount.RookieScoreTwo = 0;
_thisAccount.RookieScoreThree = 0;
//Amature
_thisAccount.AmatureRank = 0;
_thisAccount.AmatureAverage = 0;
_thisAccount.AmatureScoreOne = 0;
_thisAccount.AmatureScoreTwo = 0;
_thisAccount.AmatureScoreThree = 0;
//Semi
_thisAccount.SemiProRank = 0;
_thisAccount.SemiAverage = 0;
_thisAccount.SemiProScoreOne = 0;
_thisAccount.SemiProScoreTwo = 0;
_thisAccount.SemiProScoreThree = 0;
//Pro
_thisAccount.ProRank = 0;
_thisAccount.ProAverage = 0;
_thisAccount.ProScoreOne = 0;
_thisAccount.ProScoreTwo = 0;
_thisAccount.ProScoreThree = 0;
_thisAccount.accTricks = Account.instance.ReturnTricks();
string tName = _thisAccount.getAccName();
Debug.Log("Name: " + tName + " account " + _thisAccount.accTricks.Length);
Debug.Log("Email: " + _thisAccount.accEmail);
Debug.Log("Cash: " + _thisAccount.accCash);
Debug.Log("Attempt to fill Database info");
ConstuctDatabase(usersdb, _thisAccount);
}
private void ConstuctDatabase(DatabaseReference AccountRef, AccountData _thisAccount)
{
int num = 0;
AccountRef.RunTransaction(MutableData =>
{
num++;
List<object> account = MutableData.Value as List<object>;
if (account == null)
{
account = new List<object>();
}
else
{
Debug.Log("continue");
}
Dictionary<string, object> newAccount =
new Dictionary<string, object>();
newAccount["AccountName"] = _thisAccount.accName;
newAccount["AccountEmail"] = _thisAccount.accEmail;
newAccount["Cash"] = _thisAccount.accCash;
newAccount["Gem"] = _thisAccount.accGem;
//Ranking Values
newAccount["Rank"] = _thisAccount.Rank;
//rookie
newAccount["RookieRank"] = _thisAccount.RookieRank;
newAccount["RookieAverage"] = _thisAccount.RookieAverage;
newAccount["RookieScoreOne"] = _thisAccount.RookieScoreOne;
newAccount["RookieScoreTwo"] = _thisAccount.RookieScoreTwo;
newAccount["RookieScoreThree"] = _thisAccount.RookieScoreThree;
//Amature
newAccount["AmateurRank"] = _thisAccount.AmatureRank;
newAccount["AmateurAverage"] = _thisAccount.AmatureAverage;
newAccount["AmateurScoreOne"] = _thisAccount.AmatureScoreOne;
newAccount["AmateurScoreTwo"] = _thisAccount.AmatureScoreTwo;
newAccount["AmateurScoreThree"] = _thisAccount.AmatureScoreThree;
//Semi
newAccount["SemiProRank"] = _thisAccount.SemiProRank;
newAccount["SemiProAverage"] = _thisAccount.SemiAverage;
newAccount["SemiProScoreOne"] = _thisAccount.SemiProScoreOne;
newAccount["SemiProScoreTwo"] = _thisAccount.SemiProScoreTwo;
newAccount["SemiProScoreThree"] = _thisAccount.SemiProScoreThree;
//Pro
newAccount["ProRank"] = _thisAccount.ProRank;
newAccount["ProAverage"] = _thisAccount.ProAverage;
newAccount["ProScoreOne"] = _thisAccount.ProScoreOne;
newAccount["ProScoreTwo"] = _thisAccount.ProScoreTwo;
newAccount["ProScoreThree"] = _thisAccount.ProScoreThree;
//Trick Logic]
Dictionary<string, bool> newTricks =
new Dictionary<string, bool>();
int i = 0;
while (i < _thisAccount.accTricks.Length)
{
newTricks["Trick" + i] = _thisAccount.accTricks[i]._owned;
i++;
}
newAccount["TrickList"] = newTricks;
Debug.Log("ConstructDB1");
account.Add(newAccount);
MutableData.Value = account;
Debug.Log("ConstructDB2");
return TransactionResult.Success(MutableData);
});
}
`
Unfortunately, this is a known issue in 6.6.0. If you pay attention to the release page, I'd recommend upgrading as soon as possible.
Now an explanation of what's going on with a small workaround: an array is being serialized as effectively a dictionary with a numeric key. It's parsing numbers lexicographically (ex: it's doing some thing like 1, 10, 2, 3, 4, 5, 6...) and it breaks at 11. To work around this, rather than adding a list as you currently are, try serializing a dictionary with lexicographically ordered keys (ex: M001, M002, M003, &c). I know this isn't ideal, but it should unblock you for the time being!

How do you make buttons that have a specific length?

I'm having difficulty using a customlistrenderer class and homescreen class.
Here's my Homescreen class that contains the function generateData(), which is supposed to display a scroller of 22 buttons.
private function generateData(): void{
var list: List = new List();
list.width = 235;
list.height = 380;
list.name = "HomeScreenList";
this.addChild(list);
var rows:int = 6;
var iterator:int = 0;
var num:int = 22;
var counter:int = 0;
var obj:Object;
var heroName:Array = ["ana", "bastion", "d.va", "genji", "hanzo", "junkrat", "lucio",
"mccree", "mei", "mercy", "pharah", "reaper", "reinhardt", "roadhog", "soldier76", "symmetra",
"torbjorn", "tracer", "widowmaker", "winston", "zarya", "zenyatta"];
var temp:Array = []
obj = new Object();
while(iterator < rows){
obj.name1 = heroName[counter];
obj.image1 = myResource.getImage(heroName[counter]);
obj.name2 = heroName[counter+1];
obj.image2 = myResource.getImage(heroName[counter+1]);
obj.name3 = heroName[counter+2];
obj.image3 = myResource.getImage(heroName[counter+2]);
obj.name4 = heroName[counter+3];
obj.image4 = myResource.getImage(heroName[counter+3]);
temp.push(obj);
counter+4;
iterator++;
}
var collection:ListCollection = new ListCollection(temp);
//assign the renderer
list.itemRendererType = CustomMenuListRenderer;
list.dataProvider = collection;
list.addEventListener(Event.CHANGE, onChange);
this.addChild(list);
list.validate();
}
and the CustomMenuListRenderer class, under the initialize() function
super.initialize();
firstButton = new Button();
this.addChild(firstButton);
firstButton.x = 20;
firstButton.y = 100;
firstButton.scale = 0.60;
secondButton = new Button();
secondButton.x = 92;
secondButton.y = 100;
secondButton.scale = 0.60;
thirdButton = new Button();
thirdButton.x = 163;
thirdButton.y = 100;
thirdButton.scale = 0.60;
fourthButton = new Button();
fourthButton.x = 235;
fourthButton.y = 100;
fourthButton.scale = 0.60;
firstButton.addEventListener(Event.TRIGGERED, onTrigger);
secondButton.addEventListener(Event.TRIGGERED, onTrigger);
thirdButton.addEventListener(Event.TRIGGERED, onTrigger);
fourthButton.addEventListener(Event.TRIGGERED, onTrigger);
The problem is since the loop displays the 4 buttons each loop, an error occurs at the 23rd button(since I only specified 22 buttons but I declared 4 buttons on the CustomMenuListRenderer class) in the 6th row.
My question is how do I fix this issue?
First question, why define num manually and not use heroName.lenght? Is more secure
var heroName:Array = ["ana", "bastion", "d.va", "genji", "hanzo", "junkrat", "lucio",
"mccree", "mei", "mercy", "pharah", "reaper", "reinhardt", "roadhog", "soldier76", "symmetra",
"torbjorn", "tracer", "widowmaker", "winston", "zarya", "zenyatta"];
var num:int = heroName.lenght;
To fix your error, you have to check is heroName index exists before to get it.
Something like :
obj = new Object();
while(iterator < rows){
var objCounter:int = 1;
while(objCounter <= 4 )
{
if( counter < heroName.lenght )
{
obj["name"+objCounter] = heroName[counter];
obj["image"+objCounter] = myResource.getImage(heroName[counter]);
}
objCounter++;
counter++;
}
temp.push(obj);
iterator++;
}

How to retrieve parentaccountid from account using queryexpression and silverlight

My query returns account.name, account.account and account.parentaccountid.
I'm using Silverlight and CRM2011.
Now I'm having trouble to find out how to extract value from parentaccountid attribute.
I have silverlightextensionmethods.cs file included in my VS project, and I'm using GetAttributeValue<Guid>("parentaccountid") to get the value from parentaccountid.
The value returned is empty.
Has anyone any ideas how to accomplish this?
I can get any other attribute value, but parentaccountid in account and parentcustomerid in contact are making my life very difficult.
Code:
FIRST I CREATE QUERYEXPRESSION:
string temp="name;accountid;parentaccountid";
string[] fields = temp.Split(';');
QueryExpression query = new QueryExpression()
{
EntityName = entity,
ColumnSet = new ColumnSet { Columns = new System.Collections.ObjectModel.ObservableCollection<string>(fields) },
Criteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = parentidfield,
Operator = ConditionOperator.Equal,
Values = { id }
}
}
}
};
OrganizationRequest req = new OrganizationRequest();
req.RequestName = "RetrieveMultiple";
req["Query"] = query;
service.BeginExecute(req, new AsyncCallback(GetChildren_ExecuteCallBack), service);
NEXT I TY TO READ VALUES FORM RESPONSE
void GetChildren_ExecuteCallBack(IAsyncResult childresult)
{
List<TreeRecord> listc = new List<TreeRecord>();
try
{
OrganizationResponse childresponse = ((IOrganizationService)childresult.AsyncState).EndExecute(childresult);
EntityCollection childresults = (EntityCollection)childresponse["EntityCollection"];
if (childresults.Entities.Count > 0)
{
TreeConfig sitm = new TreeConfig();
string sdisplay = "";
string[] fields = "".Split(';');
string sid = "";
string pid = "";
foreach (Entity childentity in childresults.Entities)
{
foreach (TreeConfig sitem in Configs)
{
if (sitem.EntityName == childentity.LogicalName)
{
sitm = sitem;
}
}
TreeRecord childitem = new TreeRecord();
string sValue = "";
sdisplay = "name;accountid;parentaccountid";
fields = sdisplay.Split(';');
sid = "accountid";
pid = "parentaccountid";
int i = sdisplay.Split(';').Length;
for (int j = 0; j < i; j++)
{
try { sValue += childentity.GetAttributeValue<string>(fields[j]) + " "; }
catch (Exception ex)
{
//s = "sValue haku: " + ex.Message.ToString();
//this.ReportMessage(s.ToString());
}
}
childitem.Name = sValue;
childitem.EntityName = childentity.LogicalName;
childitem.Level = sitm.Level;
childitem.ParentEntityName = sitm.EntityName;
childitem.Color = sitm.Color;
childitem.RecordId = childentity.GetEntityId<Guid>(sid);
try { childitem.ParentId = childentity.GetAttributeValue<Guid>(pid); }
catch
{
//sb.AppendLine("guid: parentid tietoa ei löydy");
//this.ReportMessage(sb.ToString());
}
listc.Add(childitem);
}
}
}
Instead of
childentity.GetAttributeValue<Guid>(pid)
use
childentity.GetAttributeValue<EntityReference>(pid)

Resources