Cannot add new correlated record to new created record - google-app-maker

When I create new record in Google AppMaker and then try to add correlated record to this new one I get this warning in console:
com.google.apps.appmaker.client.datasource.AbstractModelDataSource
WARNING: Could not find element with key RecordKey{key=private$7,
model key=...
Both datasources are set to:
Manual save mode
Automatically load data
The problem doesn't appear when I refresh the page or try to add correlated record to other existing record.
Anybody knows what could be a reason for this error?

App Maker doesn't allow to have unsaved changes on both ends of relation, most likely it is a reason, why you recieve error message in the first case. But in theory it should work once you save one of the relation ends (first save one of the records and then link them and save again):
var countryDs = app.datasources.Country;
var capitalDs = app.datasources.Capital;
countryDs.createItem();
countryDs.item.Name = 'United States';
countryDs.saveChanges(function() {
capitalDs.createItem();
capitalDs.item.Name = 'Washington, D.C.';
capitalDs.item.Country = countryDs.item;
capitalDs.saveChanges();
});

OK, I fixed it.
I have two forms. First to create item. Second to edit data. In the first form page need to be set to:
On Detach: Clear Changes To Datasource.
Datasources need to be set to autosave.

Related

How to generate totals of fields from related model records

I'm trying to work out how to generate totals of fields from related model records.
Example: I have 2 Google Drive Table models (Projects & Stages) with a relation where 1 Project can have many Stages. The Stages model has a number of fields, one of which is Budget.
I'm trying work out how to display a Total Project Budget, which is the sum of the Budget fields of the Stages related to each Project.
I'm really stuck on getting this to work and wondering if I need to create a client script, server script, or calculated model, or if there's an easy way to do this directly within a binding.
Here is a link to a bunch of screen-grabs of what I'm trying to build, the UI and setup in App Maker:
https://www.dropbox.com/sh/wt00virvn88puyi/AACy7-fPLYFF1H9uFkvEuvgTa?dl=0
Datasource has client event onLoad, so you can calculate value in this event, find widget, which shows total, and set text of this widget.
I got it working by creating the following client script, after studying Andrey's suggestion & link (thanks!). I call the script whenever the totals need recalculating (i.e. onValueChange of existing Stages, and onAttach/Detach for new or deleted Stages. Works nicely.
function updateProjectTotals() {
var currentProject = app.datasources.Projects.item;
var totals = {ProjectName:currentProject.ProjectName, Stages:0, Progress:0, Budget:0};
var stages = currentProject.Stages;
stages.forEach(function(item){
totals.Progress += item.StageProgress;
totals.Budget += item.StageBudget;
});
totals.Stages = stages.length;
totals.Progress = (totals.Progress/totals.Stages);
var record = app.datasources.Projects.item;
record.ProjectProgress = totals.Progress;
record.ProjectBudget = totals.Budget;
}

Can't Edit/Update Certain Items In Database (Table)

I have database that I have multiple orders entered into. Everything seems to be working fine except for a few old entries which will not accept updates/changes to their Fields.
Note: The majority of the Fields are Strings with Possible Values entered via a DropDown Box.
So if I open Order A I can make adjustments just fine and those changes persist even after closing the page and coming back or refreshing.
But if I open Order B, I can make changes via the dropdowns and it looks like they have adjusted, however if I leave the page or refresh all the changes have reverted back.
One piece of info that may be helpful is that each of these orders has at least one Field that contains an entry that is no longer a Possible Value (the original entries were removed/changed per request of the client).
Maybe they are "locked" because of this? Is there a way to look at an error log for a Published app?
I can delete the "corrupt" entries and recreate them (since there are currently only a few), but I would prefer to find a better solution in case this happens again in the future.
Any help would be greatly appreciated.
It's a bug. Such field level value updates should get through.
As workaround you can update prohibited(not possible anymore) values with allowed ones in OnSave Model's Event like:
switch (record.Field) {
case "old_value_1":
record.Field = "new_value_1";
break;
case "old_value_2":
record.Field = "new_value_2";
break;
...
}
Sorry for the inconvenience.
Each deployment has its own log. Have you tried "App Settings > DEPLOYMENTS > (click on the desployment) > VIEW LOGS"?

Ax 2012 X++ Report Controller class caching

Short Version :
If an error is thrown during the execution of an SSRS report after the associated RDP temporary tables have been updated, the next time the report is run for the same parameters, code execution does not insert fresh data into said tables. Any idea why and how to prevent it?
Long Version :
I am trying to modify the run conditions of a standard report (SalesInvoiceReport) so that the original of any invoice can only be printed once. For all reprints, the "Copy preview" option should be used.
For the most part, the customization is working as intended. I used the CustInvoiceJour.PrintedOriginals field and the CustInvoiceJour.updatePrintedOriginals() (both part of Standard Ax) to maintain the number of originals that have been printed and a slight modification to the SalesInvoiceController.outputReport() method throw an error of an original is being re-printed. Below is the code added to achieve this :
...
// <A147> Code to disable reprints if an original is already printed
isOriginalPrintable = CustInvoiceJour::findRecId(custInvoiceJour.RecId).PrintedOriginals == 0;
srsPrintDestinationSettings = formLetterReport.getCurrentPrintSetting().parmPrintJobSettings();
//srsPrintMediumType = srsPrintDestinationSettings.printMediumType();
if ((printCopyOriginal == PrintCopyOriginal::Original || printCopyOriginal == PrintCopyOriginal::OriginalPrint))
{
// If no originals printed, allow prints.
// Need to re-read the CustInvoiceJour record from the table to get updated data
// If the Original is printed but the prin form is not refreshed, the form's recordset does not update to the latest data.
if(isOriginalPrintable)
{
CustInvoiceJour::updatePrinted(custInvoiceJour, (srsPrintDestinationSettings.numberOfCopies() == 0 ? 1 : srsPrintDestinationSettings.numberOfCopies()));
}
// Don't allow the original document to be printed more than once.
else
{
error(strFmt("#GLS223085", custInvoiceJour.InvoiceId, custInvoiceJour.InvoiceDate));
return;
}
}
// </A147>
...
I placed this in the SalesInvoiceContreller.outputReport() because I found similar code present there as part of standard Ax, albeit for use in specific country regions.
When user uses the Original Preview button, the error is thrown and code execution stops but the RDP temporary tables used to hold the report data have already been updated with report data (specifically the field which hold the Report title is set to Invoice).
When the user reruns the report, this time with the Copy Preview button, code execution somehow skips inserting fresh data into the temp tables (which would set the Report Title field to Invoice Copy) and the first copy output still says Invoice, defeating the requirement.

Quality Center Filters and Favorites Action

I am trying to change the filters in the display of the current user in the Defects module.
I have set the "tdc.BUGFactory.Filter" object with my filter and i can access the data, but i cannot force it to be displayed to the user! any idea on how to do that?
If i use a SQL command to store it in the common settings table, would it be possible to call an action to load the "Favorites" view i created to the user?
Thanks,
Achraf
================================================================
I found the answer, however stackoverflow doesn't allow me to post it:
I fonud the answer through SQA Forums, to force a filter you use the following
Set defectFilter = tDConenction.BugFactory.Filter ' Example to set a filter criteria
defectFilter.Field ("BG_DETECION_DATE") = "[Today]"
SetDefectsFilter defectFilter.Text
Set defectFilter = Nothing
There is also a function called GetDefectsFilter() which gets the current filter

Programicatlly visit (all) ASP.Net page(s) in a website?

In the Security model for out ASP.Net website (.Net 3.5) we store the page name:
page.GetType().Name
as the primary key in a database table to be able to lookup if a user has access to a certain page. The first time a page is visited this record is created automatically in the database.
We have exported these database statements to insert scripts, but each time a new page gets created we have to update the scripts, not a huge issue, but I would like to find an automated way to do this.
I created an attribute that I tagged a few pages with and then wrote a small process to get all the objects that have this attribute, through the reflection create an instance and insert the record using the same code to for page records mentioned above:
IEnumerable<Type> viewsecurityPages = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsDefined(typeof(ViewSecurityAttribute),false));
foreach (Type t in viewsecurityPages)
{
object obj = Activator.CreateInstance(t, false);
//clip..(This code just checks if the record already exists in the DB)
if (feature == null)
{
Attribute attb = Attribute.GetCustomAttribute(t, typeof(ViewSecurityAttribute));
if (attb != null)
{
CreateSecurableFeatureForPage((Page)obj, uow, attb.ToString());
}
}
}
The issue is that page.GetType().Name when the page goes through the actual page cycle process is something like this:
search_accounts_aspx
but when I used the activator method above it returns:
Accounts
So the records don't match the in the security table. Is there anyway to programtically "visit" a webpage so that it goes through the actual page lifecycle and I would get back the correct value from the Name parameter?
Any help/reference will be greatly appreciated.
Interesting problem...
Of course there's a (too obvious?) way to programmatically visit the page... use System.Net.HttpWebRequest. Of course, that requires the URI and not just a handle to the object. This is a "how do we get there from here?" problem.
My suggestions would be to simply create another attribute (or use that same one) which stores the identifier you need. Then it will be the same either way you access it, right?
Alternatively... why not just use a 3rd party web spider/crawler to crawl your site and hit all the pages? There are several free options. Or am I missing something?

Resources