Property list invalid for format: 200 (property lists cannot contain objects of type 'CFNull') Attempt to set a non-property-list object - titanium-mobile

I'm getting a weird error when using Ti.App.Properties.setList() method.
Here you can see that i have some values.
Console:
[INFO] : id==2251378
[INFO] : category==[object Object]
[INFO] : localteam.id==18650
[INFO] : visitorteam.id==7636
[INFO] : j==1
[INFO] : i==2
Now i getlist(); and save in a variable, and in second line create an object and initialize it. And assign some values in it.
My Code is:
var myMatchesFootball = Ti.App.Properties.getList('myMatchesFootball');
myMatchesFootballObject = new Object();
myMatchesFootballObject.matchId = "";
myMatchesFootballObject.data = "";
myMatchesFootballObject.local = "";
myMatchesFootballObject.visitor = "";
myMatchesFootballObject.index_j = "";
myMatchesFootballObject.index_i = "";
myMatchesFootballObject.matchId = json2.scores.category[e.source.star_indexi].matches.match.id;
myMatchesFootballObject.data = json2.scores.category[e.source.star_indexi];
myMatchesFootballObject.local = json2.scores.category[e.source.star_indexi].matches.match.localteam.id;
myMatchesFootballObject.visitor = json2.scores.category[e.source.star_indexi].matches.match.visitorteam.id;
myMatchesFootballObject.index_j = e.source.star_indexj;
myMatchesFootballObject.index_i = e.source.star_indexi;
myMatchesFootballObject.selectedDay = "myMatches";
myMatchesFootball.push(myMatchesFootballObject);
Ti.App.Properties.setList('myMatchesFootball', myMatchesFootball);
But my app crash and show this error in console,
The Error is:
[ERROR] : Script Error {
[ERROR] : column = 62;
[ERROR] : line = 888;
[ERROR] : message = "Attempt to insert non-property list object (\n {\n data = {\n \"file_group\" = brazil;\n gid = 1139;\n id = 1139;\n matches = {\n date = \"Jan 11\";\n \"formatted_date\" = \"11.01.2017\";\n match = (\n {\n \"commentary_available\" = \"\";\n date = \"Jan 11\";\n events = \"<null>\";\n \"fix_id\" = 2042614;\n \"formatted_date\" = \"11.01.2017\";\n ht = {\n score = \"\";\n };\n id = 2251377;\n localteam = {\n goals = \"?\";\n id = 7139;\n name = \"Cajazeirense de Desportos\";\n };\n \"static_id\" = 2159519;\n status = \"23:30\";\n time = \"23:30\";\n timer = \"\";\n v = 0;\n venue = \"\";\n visitorteam = {\n goals = \"?\";\n id = 17805;\n name = \"Botafogo PB\";\n };\n },\n {\n \"commentary_available\" = \"\";\n date = \"Jan 11\";\n events = \"<null>\";\n \"fix_id\" = 2042611;\n \"formatted_date\" = \"11.01.2017\";\n ht = {\n score = \"\";\n };\n id = 2251378;\n localteam = {\n goals = \"?\";\n id = 18650;\n name = CSP;\n };\n \"static_id\" = 2159516;\n status = \"23:30\";\n time = \"23:30\";\n timer = \"\";\n v = 0;\n venue = \"\";\n visitorteam = {\n goals = \"?\";\n id = 7636;\n name = \"Treze PB\";\n };\n },\n {\n \"commentary_available\" = \"\";\n date = \"Jan 11\";\n events = \"<null>\";\n \"fix_id\" = 2042610;\n \"formatted_date\" = \"11.01.2017\";\n ht = {\n score = \"\";\n };\n id = 2251379;\n localteam = {\n goals = \"?\";\n id = 7366;\n name = \"Internacional PB\";\n };\n \"static_id\" = 2159515;\n status = \"23:30\";\n time = \"23:30\";\n timer = \"\";\n v = 0;\n venue = \"\";\n visitorteam = {\n goals = \"?\";\n id = 20327;\n name = Paraiba;\n };\n },\n {\n \"commentary_available\" = \"\";\n date = \"Jan 11\";\n events = \"<null>\";\n \"fix_id\" = 2042612;\n \"formatted_date\" = \"11.01.2017\";\n ht = {\n score = \"\";\n };\n id = 2251380;\n localteam = {\n goals = \"?\";\n id = 27182;\n name = \"Serrano PB\";\n };\n \"static_id\" = 2159517;\n status = \"23:30\";\n time = \"23:30\";\n timer = \"\";\n v = 0;\n venue = \"\";\n visitorteam = {\n goals = \"?\";\n id = 7150;\n name = \"Auto Esporte\";\n };\n },\n {\n \"commentary_available\" = \"\";\n date = \"Jan 11\";\n events = \"<null>\";\n \"fix_id\" = 2042613;\n \"formatted_date\" = \"11.01.2017\";\n ht = {\n score = \"\";\n };\n id = 2251381;\n localteam = {\n goals = \"?\";\n id = 7619;\n name = \"Sousa EC\";\n };\n \"static_id\" = 2159518;\n status = \"23:30\";\n time = \"23:30\";\n timer = \"\";\n v = 0;\n venue = \"\";\n visitorteam = {\n goals = \"?\";\n id = 7195;\n name = Campinense;\n };\n }\n );\n };\n name = \"Brazil: Campeonato Paraibano\";\n };\n date = \"11.01.2017\";\n \"index_i\" = 2;\n \"index_j\" = 1;\n local = 18650;\n matchId = 2251378;\n name = \"Brazil: Campeonato Paraibano\";\n selectedDay = myMatches;\n time = \"23:30\";\n visitor = 7636;\n }\n) for key myMatchesFootball";
[ERROR] : sourceURL = "file:///Users/Apple/Library/Developer/CoreSimulator/Devices/1C82A7E8-F480-4FE1-A0F2-C6F713774B0D/data/Containers/Bundle/Application/500CCBD6-B81D-4D6A-AB8E-0C8E24E379D8/Tipping%20Hub.app/alloy/controllers/football_window_detail.js";
[ERROR] : stack = "[native code]\nfile:///Users/Apple/Library/Developer/CoreSimulator/Devices/1C82A7E8-F480-4FE1-A0F2-C6F713774B0D/data/Containers/Bundle/Application/500CCBD6-B81D-4D6A-AB8E-0C8E24E379D8/Tipping%20Hub.app/alloy/controllers/football_window_detail.js:888:62";
[ERROR] : }
But when i comment this line it working fine,
myMatchesFootballObject.data = json2.scores.category[e.source.star_indexi];
I am also try this but not working,
myMatchesFootballObject.data = new Object;

The reason why you are having this error is because you are trying to save nested objects and the setList/getList API does not support it, therefore you get the error Attempt to insert non-property list object
The solution for that is to stringify that object and store it, but, I would not recommend that as a best practice. You should probably use a database using Alloy models instead of saving this in the Ti.App.Properties
A few things that you can change in your code to improve it:
Default the variable to an empty array.
var myMatchesFootball = Ti.App.Properties.getList('myMatchesFootball', []);
Instead of calling new Object, just declare the object and assign the values right to it. (Don't forget the var at the beginning)
var myMatchesFootballObject = {
matchId: json2.scores.category[e.source.star_indexi].matches.match.id,
data: JSON.stringify(json2.scores.category[e.source.star_indexi]),
// Add other values
};
The rest is ok:
myMatchesFootball.push(myMatchesFootballObject);
Ti.App.Properties.setList('myMatchesFootball', myMatchesFootball);

Related

Contat 2 Lists from different tables into 1 and use AsQueryable()

Attempting to return the below 2 lists into something I can then query against.
var people = (from c in _context.FollowingPeople
select new Models.Following.FollowingModel
{
Id = c.Id,
MediaTypeId = c.MediaTypeId,
Title = c.Title,
ClientId = c.ClientId,
Person = (from p in _context.SocialMediaPeople
where p.Id == c.SocialMediaId
select new Models.SocialMediaPeople
{
Id = p.Id,
Photo = p.Photo
}).FirstOrDefault()
});
var generic = (from c in _context.FollowingGeneric
select new Models.Following.FollowingModel
{
Id = c.Id,
MediaTypeId = c.MediaTypeId,
Title = c.Title,
ClientId = c.ClientId,
Person = null
});
var temp = people.Concat(generic).ToList();
//var data = temp.AsQueryable();
if (!string.IsNullOrEmpty(filter))
{
data = data.Where(filter);
}
data = data.Where(x => x.ClientId == ClientId);
return await data
.GetPaged(page, pageSize);
I have tried join, concat, even Zip but it results in various errors such as
(Unable to translate set operation after client projection has been applied. Consider moving the set operation before the last 'Select' call.)
So I finally got this working, the trick is to not perform any queries on the data until AFTER the concat. Th below works...
var queryA =
from c in _context.Set<FollowingPeople>()
select new Models.Following.FollowingModel
{
Id = c.Id,
MediaTypeId = c.MediaTypeId,
Title = c.Title,
ClientId = c.ClientId
};
var queryB =
from c in _context.Set<FollowingGeneric>()
select new Models.Following.FollowingModel
{
Id = c.Id,
MediaTypeId = c.MediaTypeId,
Title = c.Title,
ClientId = c.ClientId
};
var queryC =
from c in _context.Set<FollowingPublication>()
select new Models.Following.FollowingModel
{
Id = c.Id,
MediaTypeId = c.MediaTypeId,
Title = c.Title,
ClientId = c.ClientId
};
var data = (from v in queryA.Union(queryB).Union(queryC)
select new Models.Following.FollowingModel
{
Id = v.Id,
MediaTypeId = v.MediaTypeId,
Title = v.Title,
ClientId = v.ClientId,
})
.AsNoTracking()
.AsQueryable();
data = data.Where(x => x.ClientId == ClientId);
return await data.GetPaged(page, pageSize);

LinqToDB Exception cannot be converted to SQL

Hello I have an issue with this query
var queryGrouped = queryFiltered
.GroupBy(c => new { c.Id, c.TableOneId, c.TableOneName, c.TableTwoId, c.TableTwoName, c.TableTwoCode, c.TableThreeId, c.TableThreeName, c.Description, c.EffectiveDate, c.CreatedBy, c.ServiceGroupName })
.DisableGuard()
.Select(cg => new Model
{
Id = cg.Key.Id,
TableOneId = cg.Key.TableOneId,
TableOneName = cg.Key.TableOneName,
TableTwoId = cg.Key.TableTwoId,
TableTwoCode = cg.Key.TableTwoCode,
TableTwoName = cg.Key.TableTwoName,
TableThreeId = cg.Key.TableThreeId,
TableThreeName = cg.Key.TableThreeName,
Description = cg.Key.Description,
EffectiveDate = cg.Key.EffectiveDate,
EffectiveDateText = cg.Key.EffectiveDate != null ? cg.Key.EffectiveDate.Value.ToString("MM/dd/yyyy") : string.Empty,
ServiceGroupName = string.Join(", ", cg.Select(g => g.ServiceGroupName).Distinct()),
CreatedBy = cg.Key.CreatedBy
}).OrderBy(x => x.ServiceGroupName).ToListAsync();
If i run this when try to order by the field ServiceGroup it returns this message
LinqToDB.Linq.LinqException: ''Join(", ", cg.Select(g => g.ServiceGroupName).Distinct())' cannot be converted to SQL.'
So I don't know how to order by this field ServiceGroupName, thanks for any answer.
I would suggest to make grouping on the client side. Note that I have removed ServiceGroupName from grouping key.
var data = await queryFiltered
.Select(c => new {
c.Id,
c.TableOneId,
c.TableOneName,
c.TableTwoId,
c.TableTwoName,
c.TableTwoCode,
c.TableThreeId,
c.TableThreeName,
c.Description,
c.EffectiveDate,
c.CreatedBy,
c.ServiceGroupName
})
.ToListAsync();
var queryGrouped = data
.GroupBy(c => new { c.Id, c.TableOneId, c.TableOneName, c.TableTwoId, c.TableTwoName, c.TableTwoCode, c.TableThreeId, c.TableThreeName, c.Description, c.EffectiveDate, c.CreatedBy })
.Select(cg => new Model
{
Id = cg.Key.Id,
TableOneId = cg.Key.TableOneId,
TableOneName = cg.Key.TableOneName,
TableTwoId = cg.Key.TableTwoId,
TableTwoCode = cg.Key.TableTwoCode,
TableTwoName = cg.Key.TableTwoName,
TableThreeId = cg.Key.TableThreeId,
TableThreeName = cg.Key.TableThreeName,
Description = cg.Key.Description,
EffectiveDate = cg.Key.EffectiveDate,
EffectiveDateText = cg.Key.EffectiveDate != null ? cg.Key.EffectiveDate.Value.ToString("MM/dd/yyyy") : string.Empty,
ServiceGroupName = string.Join(", ", cg.Select(g => g.ServiceGroupName).Distinct()),
CreatedBy = cg.Key.CreatedBy
})
.OrderBy(x => x.ServiceGroupName)
.ToList();

How can I get the entity attributes metadata list?

Dynamics 365 v8.2.2.
Why attributesMetadata is null? How can I get the entity attributes metadata list?
{
var req = new RetrieveEntityRequest {
LogicalName = "opportunity",
RetrieveAsIfPublished = true,
};
var resp = srv.Execute(req) as RetrieveEntityResponse;
var entityMetadata = resp.EntityMetadata;
var attributesMetadata = entityMetadata.Attributes; // null
}
You need to set EntityFilters in request like:
EntityFilters = EntityFilters.All
Or
EntityFilters = EntityFilters.Attributes
The complete snippet as follows:
RetrieveEntityRequest retrieveEntityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Attributes,
LogicalName = "opportunity"
};
RetrieveEntityResponse retrieveOpptyEntityResponse(RetrieveEntityResponse)service.Execute(retrieveEntityRequest);
EntityMetadata opptyEntity = retrieveOpptyEntityResponse.EntityMetadata;
By default, EntityFilters.Default only entity information will be retrieved, that’s why you have empty attribute list.
Read more

DevExpress MVC Pivotgrid: How to summarize/aggregate differently on grouping levels

I have a DevExpress MVC PivotGrid. It has a header that at the highest level is Quarter, then Months, then Weeks. The data that is passed to the grid needs to sum the data for the week, but average the week data for month and average the data (either week or month) for the quarter.
Here is a screenshot of the grid:
I want to have the weeks 201632, 201633, 201634, 201635 to be 0.1, but July 2016 should be 0.1 also (as that is the average) and same for September. Then 2016 Q2, 2016 Q4 should also have 0.1 (as this is the average).
Here is the code for the grid fields
settings.Fields.Add(field =>
{
field.Area = PivotArea.ColumnArea;
field.AreaIndex = 0;
field.TotalsVisibility = PivotTotalsVisibility.None;
field.CellStyle.Wrap = DefaultBoolean.False;
field.Width = 150;
field.Caption = "Quarter Year";
field.FieldName = "YYYYQ";
field.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
field.Options.AllowSort = DefaultBoolean.False;
field.Options.AllowFilter = DefaultBoolean.False;
});
settings.Fields.Add(field =>
{
field.Area = PivotArea.ColumnArea;
field.AreaIndex = 1;
field.TotalsVisibility = PivotTotalsVisibility.None;
field.CellStyle.Wrap = DefaultBoolean.False;
field.Width = 150;
field.Caption = "Month Year";
field.FieldName = "YYYYMM";
field.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
field.Options.AllowSort = DefaultBoolean.False;
field.Options.AllowFilter = DefaultBoolean.False;
});
settings.Fields.Add(field =>
{
field.Area = PivotArea.ColumnArea;
field.AreaIndex = 2;
field.CellStyle.Wrap = DefaultBoolean.False;
field.Width = 150;
field.Caption = "Work Week";
field.FieldName = "YYYYWW";
field.Options.AllowSort = DefaultBoolean.False;
field.Options.AllowFilter = DefaultBoolean.False;
});
settings.Fields.Add(field =>
{
field.Area = PivotArea.DataArea;
field.FieldName = summaryField;
field.Caption = summaryField;
field.CellFormat.FormatType = FormatType.Numeric;
field.CellFormat.FormatString = format;
});
I tried using
field.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Average;
in Quarter and Month but that had no effect. I have tried a bunch of other things but nothing seems to change the calculations.
Any suggestions?
I figured it out. I needed to use a Custom Summary type
Here is the code for the PivotGrid
#using DevExpressPivotGridTest;
#{
string summaryField = ViewBag.SummaryField;
WWMMQ wwmmq = new WWMMQ();
}
#Html.DevExpress().PivotGrid(settings =>
{
settings.Name = "PivotGridProject";
settings.CallbackRouteValues = new { Controller = "PivotGrid", Action = "Project"};
settings.OptionsPager.RowsPerPage = 100;
settings.OptionsView.ShowFilterHeaders = false;
settings.OptionsView.ColumnTotalsLocation = PivotTotalsLocation.Near;
settings.CustomSummary = (sender, e) =>
{
int nbrWWs;
string fieldName = "";
if (e.ColumnField == null)
fieldName = "";
else
fieldName = e.ColumnField.FieldName;
switch (fieldName)
{
case "YYYYMM":
nbrWWs = wwmmq.GetWorkWeeksInMonth(e.ColumnFieldValue.ToInt());
e.CustomValue = e.SummaryValue.Summary.ToDecimal() / nbrWWs;
break;
case "YYYYQ":
nbrWWs = wwmmq.GetWorkWeeksInQuarter(e.ColumnFieldValue.ToInt());
e.CustomValue = e.SummaryValue.Summary.ToDecimal() / nbrWWs;
break;
case "YYYYWW":
default:
e.CustomValue = e.SummaryValue.Summary;
break;
}
};
settings.Fields.Add(field =>
{
field.Area = PivotArea.RowArea;
field.AreaIndex = 0;
field.FieldName = "ProjectName";
field.Caption = "Project";
field.Options.AllowFilter = DefaultBoolean.False;
});
settings.Fields.Add(field =>
{
field.Area = PivotArea.RowArea;
field.AreaIndex = 2;
field.FieldName = "SupplierName";
field.Caption = "Supplier";
field.Options.AllowFilter = DefaultBoolean.False;
});
settings.Fields.Add(field =>
{
field.Area = PivotArea.ColumnArea;
field.AreaIndex = 0;
field.TotalsVisibility = PivotTotalsVisibility.None;
field.CellStyle.Wrap = DefaultBoolean.False;
field.Width = 150;
field.Caption = "Quarter Year";
field.FieldName = "YYYYQ";
field.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
field.Options.AllowSort = DefaultBoolean.False;
field.Options.AllowFilter = DefaultBoolean.False;
});
settings.Fields.Add(field =>
{
field.Area = PivotArea.ColumnArea;
field.AreaIndex = 1;
field.TotalsVisibility = PivotTotalsVisibility.None;
field.CellStyle.Wrap = DefaultBoolean.False;
field.Width = 150;
field.Caption = "Month Year";
field.FieldName = "YYYYMM";
field.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
field.Options.AllowSort = DefaultBoolean.False;
field.Options.AllowFilter = DefaultBoolean.False;
});
settings.Fields.Add(field =>
{
field.Area = PivotArea.ColumnArea;
field.AreaIndex = 2;
field.CellStyle.Wrap = DefaultBoolean.False;
field.Width = 150;
field.Caption = "Work Week";
field.FieldName = "YYYYWW";
field.Options.AllowSort = DefaultBoolean.False;
field.Options.AllowFilter = DefaultBoolean.False;
});
settings.Fields.Add(field =>
{
field.SummaryType = PivotSummaryType.Custom;
field.Area = PivotArea.DataArea;
field.FieldName = summaryField;
field.Caption = summaryField;
field.CellFormat.FormatType = FormatType.Numeric;
field.CellFormat.FormatString = "n2";
});
}).Bind(Model).GetHtml()
public class WWMMQ
{
private List<MyDates> dates;
public WWMMQ()
{
dates = MyDates.Get();
}
public WWMMQ(string startDate, string endDate)
{
dates = MyDates.Get(startDate, endDate);
}
public int GetWorkWeeksInMonth(int month)
{
// some months have 4, some months have 5
return dates.Count(d => d.YYYYMM == month);
}
public int GetWorkWeeksInQuarter(int quarter)
{
// most quarters have 13, some quarters have 14
return dates.Count(d => d.YYYYQ == quarter);
}
The trick was to define a Custom Summary function. DevExpress already calculates all the aggregates. For the week summary, I just use the Sum value as normal, but for the month and quarter, I use the Sum but divide it by the number of weeks in either the month or quarter to get the average.

LINQ Group By Subtotal & Total

I have a Batch with BatchItems entered by multiple users. I'm trying to not only get the subtotal per user for a single batch, but also grand total for that same batch regardless of the user grouping. Its this last part that I can't figure out. How might I get that total in order to return it as a list?
from b in context.BatchItem
where b.BatchId == batchId
group b by b.CreatedByUser into g
select new
{
BatchName = g.FirstOrDefault<BatchItem>().Batch.Name,
User = g.Key,
UserBatchCount = g.Count<BatchItem>(),
// something like this is what I can't figure out
TotalBatchCount = b.Count<BatchItem>()
}
Not sure, but try this:
from b in context.BatchItem
let cnt = context.BatchItem.Count()
b.BatchId == batchId
group b by b.CreatedByUser into g
select new
{
BatchName = g.FirstOrDefault<BatchItem>().Batch.Name,
User = g.Key,
UserBatchCount = g.Count<BatchItem>(),
// something like this is what I can't figure out
TotalBatchCount = cnt
}
var batch1 = new { Name = "Batch A", BatchId = 1, CreatedByUser = "David" };
var batch2 = new { Name = "Batch A", BatchId = 1, CreatedByUser = "Mike" };
var batch3 = new { Name = "Batch B", BatchId = 2, CreatedByUser = "Cathy" };
var batch4 = new { Name = "Batch B", BatchId = 2, CreatedByUser = "Cathy" };
var batch5 = new { Name = "Batch B", BatchId = 2, CreatedByUser = "David" };
var batch6 = new { Name = "Batch C", BatchId = 3, CreatedByUser = "Henry" };
var batchItem = new[] { batch1, batch2, batch3, batch4, batch5, batch6 }.ToList();
var result =
batchItem.Where(b => b.BatchId == batchId)
.GroupBy(b => b.BatchId, b => b)
.SelectMany(g =>
g.GroupBy(c => c.CreatedByUser, c => c)
.SelectMany(sg =>
sg.Select(c => new
{
BatchName = g.First().Name,
UserName = c.CreatedByUser,
UserBatchCount = sg.Count(),
TotalBatchCount = g.Count()
})
)
);
Audit Log: Removed previous two code blocks.

Resources