The required QueryBuildDataSource was not found in the Query associated with the FormDataSource - axapta

I've extended the SalesTableListPage to include a new column taken from a display method on CustTable now my users are getting the error:
The required QueryBuildDataSource was not found in the Query associated with the FormDataSource . The QueryBuildDataSource should have the same name and table ID as the FormDataSource.
To gain access to the display method I had to:
Add CustTable to the SalesTableListPage Query
Re-Select the SalesTableListPage Query on the Data Sources node of the SalesTableListPage Form.
Add a new StringEdit on the grid and set it to CustTable CityName_BR
I can't replicate this error with my admin or my non-admin user and I don't understand where this error comes from.
One post says that if you have a Query on the menu item that opens the Form then that query needs the same data sources as the query on the form. But I don't have a query on my menu item
Other suggestions state that I need to add the new data source "in the Table related queries". I am unaware of such a setting in AX 2012
Other suggestions refer to queries written in code. mine are AOT queries
Update: It seems the reason I wasn't getting the error was that I had the CueGroup EPCustRelatedInfo or just CustRelatedInfo collapsed. When I unfold this part I am getting the error as well.
Resolving that Cue Group has led me to several menuitems with queries attached. The culprit seems to be the SalesTableListPageOpen menu item and query of the same name (which references the query I have changed).
I am however still confused as to how to actually fix the error since the SalesTableListPageOpen query just says Composite Query\SalesTableListPage. Unsetting/resetting the referenced query, restoring and re-compiling the query has not had any effect...

I think one of your suggested solutions is probably correct. Just investigate the query though and you should be able to figure out what's happening.
At the bottom of \Classes\SalesTableListPageInteraction\initializeQuery just put:
info(_query.toString());
Then open the menus All sales orders and Open sales orders and you'll see the query differences. Then repeat opening various menu items with different users and see what results.
You may need to move the location of the info line, but the concept is there.

Related

Get exception details from a Azure Monitor Workbook

In application insights I can click on an exception and find nicely formatted information about it if I click on it.
This could look like this:
I would like to archive the same in an Azure Workbook. Here I can display all my exceptions with the KQL Term "Exceptions".
With the column settings I was hoping to be able to create a link to the Application insights page that shows me the same result like in the picture above.
I use this configuration:
Now I have a link, but when I click it there is just an empty pane:
Is there anything I misunderstand?
How do I need to configure my column settings to get a direct link to the Exception details like in clicking on the same item in Application Insights?
While not super obvious, the info bubble for the link settings shows:
The value in the column is expected to be an itemId of an exception telemetry item.
So as long as your query returns the itemId field, you can map that in the column settings:
(also, iirc, if the query returns a timestamp column, the details view will try to narrow down its search to just use a range around that time instead of trying to query a larger amount of time to find an item with that id)
Edit to add: if you are using thee Log Analytics based schema, AppExceptions the field is there but missing from documentation and the schema, there is an _ItemId field that is this field. I'm working with the App Insights/ Log Analytics teams to get this properly documented there.
Also, even if you're using the log analytics based app insights, you can also always query through the "app insights" resource and use the app insights schema the "old" way as well. (unless you're doing something specific in log analytics that the AI based way doesn't have?)
example:
left is query against app insights schema, with exceptions table and itemId column
right is query against logs schema, with AppExceptions table and _ItemId field, returning the same exact item by that id value. you can seee that the _ItemId field shows red squiggles like it isn't valid, but that is incorrect, you'll get the right row if you run the query.

How to programmatically link newly created records to a record from another table

Thanks in advance for your advice!
Background
I’m creating a database to track orders placed by customers.
An ‘Orders’ table stores general details about an order like the customer’s name, order date, and delivery-required date.
A separate ‘Order_Items’ table stores the specific items that the customer has ordered.
The is a one-to-many relationship between the ‘Orders’ table and ‘Order_Items’ table, i.e. one ‘Order’ can have many ‘Order_Items’, but each ‘Order_Item’ must be associated with only one ‘Order’.
Current State
Currently, I have a page where the user creates a new ‘Order’ record. The user is then taken to another page where they can create as many ‘Order_Item’ records as are needed for the order.
Desired State
What I would like to achieve is: When a user creates new ‘Order_Item’ records, it automatically allocates the current ‘Order’ record as the foreign key for the new ‘Order_Item’ record.
What I've Tried So Far
Manual Action By The User: One way of establishing the link between an 'Order' and all of its 'Order_Items' would be to add a drop-down widget which which effectively asks the user something like "Which order number do all of these items belong to"? The user's action would then establish the link between the two tables and associate one 'Order' with many 'Order_Items'. However, my goal is for this step to be handled programatically instead.
Official Documentation: I’ve referred to the offical documentation which was useful, but as I'm still learning I don’t really know exactly what to search for. The prefetch feature appeared promising but does not actually establish a link; it just loads associated records more efficiently.
App Maker Tutorials: I found an App Maker tutorial which creates an HR App where a user can create a list of ‘Departments’, then create a list of ‘Employees’, and then link an ‘Employee’ to a ‘Department’. However, in the example app this connection is established manually by the user. In my desired state I would like the link to be established programatically.
Manual Save Mode:
I’ve also tried switching to manual save mode so that the user has to create a draft ‘Orders’ record and then several draft ‘Order Items’ records and then save them all at once. However, I haven’t managed to make this work. I’m not sure whether the failure of this approach is because 1) I’m try to create draft records on more than one table, 2) I’m just not doing it correctly, or 3) I thought I read somewhere that draft records are deprecated.
Other Ideas
I'm very new to this field and am may be wrong, but I have a feeling I may need to use some scripting to establish the link. For example, maybe I could use a global variable to remember which 'Order' the user creates. Then, for each 'Order_Item' I could use the onBeforeCreate event to trigger a script that establishes the link between the 'Order_Item' and the 'Order' that was remembered from the previously established global variable.
Updated Question
Thanks Markus and Morfinismo for your answers. I have been using both answers with some success.
Morfinismo: I've successfully used the code you directed me to on existing records but cannot seem to get it to work for newly created records.
For example:
widget.datasource.createItem(); // This creates a new record
var managerRecord = app.datasources.Manager.item; // This sets the Manager of the currently selected parent record as a variable successfully.
var teamRecord = app.datasources.Teams.item; // This attempts to set the Manager of the currently selected record as a variable. However, the record that was created in line 1 is not selected. Therefore, App Maker does not seem to know which record this line of code relates to and returns the error Cannot set property ‘Manager’ of null.
// Assign the manager to the team.
teamRecord.Manager = managerRecord; // This successfully assigns the manager but only in cases where the previous line of code was successful (i.e. existing records and not newly created ones).
Do you have any suggestions or comments on how to apply this code to records that are created by the initial line of code in line 1?
I have found the easiest way to create related items for situations such as yours is to actually import a form with the datasource set to Parent: Child (relation) or Parent: Child (relation) (create). So in your case the datasource would need to be set to Order: Order_Items (relation).
You can get this accomplished in two different ways using the form widget wizard:
Option 1:
If your page datasource is set to Order_Items, drag your form on your page.
In the datasource selection section, your datasource in the form widget should default to `Inherited: Order_Items'. Click the 'Advanced' button in the bottom left corner, then from the datasources category find Order as your datasource, then select relations in the next field, and then Order_Items in the next field, choose 'Insert only' or 'Edit' form and then the appropriate fields you want in the form.
Now every item that gets created in that form will automatically be a child record of the currently selected record in your Order datasource.
Option 2:
If your page datasource is set to Order, drag your form on your page.
In the datasource selection section, your datasource in the form widget should default to Inherited: Order. Scroll down in your datasource selection section until you find Order: Order_Items (relation), then choose 'Insert only' or 'Edit' form and then the appropriate fields you want in the form.
Now every item that gets created in that form will automatically be a child record of the currently selected record in your Order datasource.
In your Order model, make sure that the security setting is set appropriately that a user is allowed to create relations of Order_Items in Order. That is the simplest approach in my opinion since you don't have to hard code the parent into your form or client/server scripts. It is automatically based on the currently selected parent, and is essentially doing the same thing that #Morfinismo explained in the client script section.
The comment I placed under your question included a link to the official documentation that explains what you need. Anyways, your question is not clear enough to determine whether you are creating the records via client script or server script, hence this is a very general answer.
To manage relations via client script:
var managerRecord = app.datasources.Manager.item;
var teamRecord = app.datasources.Teams.item;
// Assign the manager to the team.
teamRecord.Manager = managerRecord;
// Changes are saved automatically if the datasource in auto-save mode
// Add a team member to a Manager's team.
// Note: Retrieve Members on the client before proceeding, such as by using prefetch option in datasource - datasources Team -> Members)
var engineerRecord = app.datasources.TeamMember.item;
teamRecord.Members.push(engineerRecord);
To manage relations via server script:
// Get the record for the Team to modify.
var teamRecord = app.models.Teams.getRecord("team1");
// Assign a manager to the Team.
var managerRecord = app.models.EmployeeDB.getRecord("manager1");
teamRecord.Manager = managerRecord;
// Note: The new association is not saved yet
// Assign a team member to the Team.
var engineerRecord = app.models.EmployeeDB.getRecord("engineer1");
teamRecord.Members.push(engineerRecord);
// Save both changes to the database.
app.saveRecords([teamRecord]);
The above information is taken directly from the official documentation, which like I said, I referred to in the comment I placed under your question.

Using a table display method in a query or view

I'm trying to make a query against the table HcmWorker and related.
But i want to figure out how to get the result of the display method HcmWorker.primaryDepartmentName() into it's own field in my query.
I also tried creating a view to execute the function via a ViewMethod but that doesn't seem to work as ViewMethods only inject code into the final query against the view.
I'm NOT making a form. The end result has to come through the QueryService.
Sorry, but what you are trying to do is not possible.
You could calculate a non stored field in the postLoad method, but that would impact every access to your table, and it would most likely not work in the context of a query service.

SchemaTitleCriteria yield no results in SDL Tridion Broker Query

I have a simple SDL Tridion 2011 SP1 Broker Query to retrieve a list of Component URIs. All of my Components are embedded on Pages, and not using Dynamic Component Templates. The following code returns 50 results (which is to be expected). One of which is the URI tcm:123-456-16.
List<Criteria> criteria = new List<Criteria>();
criteria.Add(new ItemTypeCriteria(16));
criteria.Add(new PublicationCriteria(337));
Query query = new Query(CriteriaFactory.And(criteria.ToArray<Criteria>()));
String[] results = query.ExecuteQuery();
The Component tcm:123-456-16 is based on a Schema with the name “News Portal”. I would like to add additional criteria to my query so that I only get items based on that Schema, so I tried the following code:
List<Criteria> criteria = new List<Criteria>();
criteria.Add(new ItemTypeCriteria(16));
criteria.Add(new PublicationCriteria(337));
criteria.Add(new SchemaTitleCriteria("News Portal"));
Query query = new Query(CriteriaFactory.And(criteria.ToArray<Criteria>()));
String[] results = query.ExecuteQuery();
This returns no results at all. I have double checked my Schema name. Is this response expected? Does the SchemaTitleCriteria require the Components to be published as Dynamic Component Presentations. Any advice would be greatly appreciated.
Yes and No on DCPs. You don't need to have all your components published as Dynamic Component Presentations (DCPs). We noticed the same and observed that if you don't publish at least one DCP based on the schema, the schema title does not get published into Schemas table of the Tridion Broker DB (not sure it is by design). Once you publish one DCP based on the schema, the schema title is stored and subsequent queries work, but until you publish that first one you will not get any.
However in practical scenario, you do broker queries to get the dcps so you should not see this behavior except a mistake or someone missed it.
Why would the component be present in the first result set, but not in the second?
I suspect this is unintended behaviour and worth raising with SDL.
To fix it you'll need to use ItemSchemaCriteria instead of SchemaTitleCriteria and obtain the components based on the schema ID, rather than the schema title.
To use the SchemaTitleCriteria I should imagine you need to have at least published one component based on the news portal schema alonside a dynamic component template so that the content delivery database contains the schema title information.

How to remove traces of Fields that belonged to a module content type?

I am trying to learn how to create a custom content type programmatically from within my module.
However, after uninstalling and reinstalling my module I was getting an error stating that one or more of the fields I was trying to create could not be created because they already exist.
So I went hacking through my databse, removing the content type and all tables that belonged to it.
Same result -- field already exists.
Next I went to the Drupal API website looking for ways to delete fields and field instances, and came across
field_delete_field()
and
field_delete_instance()
I made a php page to try to delete the fields that I had created, only to get an error stating that the table I was trying to delete does not exist.
So I'm kinda stuck -- I can't create the fields because they already exist, and I can't delete them because they don't exist!
BTW the code I was modeling my module after is the code found in the "node_example" section of the Drupal examples module.
Ouch, deleting the database tables manually is never a good idea - Drupal's not that forgiving :)
Just to address the code in your install/enable hook, wrap the field creation in:
if (!field_info_field('field_name')) {
field_create_field(...
}
That will stop the problem happening again. Or if you don't want to do that, make sure the field is deleted in the uninstall/disable hook. Obviously that method would potentially result in data loss.
To address the current problem, follow this process:
Completely uninstall (not just disable) your custom module. If it's in an inconsistent state, just delete its row in the system table.
Delete all traces of the field from the field_config and field_config_instance tables.
Truncate all the cache tables manually (any table beginning with cache_).
Not strictly necessary but clear up any lingering content:
$nids = db_query('SELECT nid FROM {node} WHERE type = :type', array(':type' => 'type'))->fetchCol();
node_delete_multiple($nids);
That ought to do it.
Any time you delete a field, through the UI or programatically you'll need to either run cron or call field_purge_batch() to 'hard' delete the fields as they're only marked for deletion in the first instance.

Resources