i wrote a query as follows and i want to block multiple selection for accountnum in query.
Is there any way for to do this in code ?
Query = new Query();
qbdsVendTransOpen = Query.addDataSource(tableNum(VendTransOpen));
qbdsVendTrans = qbdsVendTransOpen.addDataSource(tableNum(VendTrans));
qbdsVendTrans.relations(true);
qbdsVendTrans.joinMode(JoinMode::InnerJoin);
qbdsVendTable = qbdsVendTrans.addDataSource(tableNum(VendTable));
qbdsVendTable.relations(true);
qbdsVendTable.joinMode(JoinMode::InnerJoin);
qbdsVendTable.addRange(fieldNum(VendTable,accountNum));
I don't think this can be done easily within the query dialog. I would suggest locking the range (see #Jonathan Bravetti's answer) and building a custom dialog or field before calling the query dialog. The user would enter the account number in the custom ui and then you can use code to transfer the entered value to the query.
If you want lock your range add this line:
qbdsVendTable.addRange(fieldNum(VendTable,accountNum)).status(rangestatus::Locked);
Related
Dears,
I'm using Microsoft Dynamics AX2012 R3
The Case: I want to make a custom lookup in Inventory Management ==> Journals ==> Item Transactions ==> Movement ==> Lines
I want to relate the Item Id to show all lines in the SalesLines Table in order to get the ItemId and It's dimensions (Config/Size/Color/Style) and when I select it I want to move the selection to the movement line.
My Solution:
Step1: I've made a custom view (viewCustomItemId) that shows all SalesLines tables and related to InventDim to show the dimensions.
Step2: I've made a custom form (frmCustomItemId) and added the view (viewCustomItemId) as a datasource and added all fields to a grid
Step3: In the form (InventJournalMovement) I've overrided the lookup method and added below code
Args args = new Args();
viewCustomItemId _viewCustomItemId;
args.name(formstr(frmCustomItemId));
args.caller(element);
newPopup = classFactory.formRunClass(args);
this.performFormLookup(newPopup);
newPopup.init();
newPopup.wait();
if (newPopup.closedOk())
{
_viewCustomItemId = newPopup.docCursor();
InventJournalTrans.ItemId = _viewCustomItemId.ItemId;
InventDim.configId = _viewCustomItemId.configId;
InventDim.InventSizeId = _viewCustomItemId.InventSizeId;
InventDim.InventColorId = _viewCustomItemId.InventColorId;
InventDim.InventStyleId = _viewCustomItemId.InventStyleId;
InventJournalTrans_DS.research();
}
Problem: When the lookup form is closed all fields are set to the movement line but I get warning message (Field 'Item number' must be filled in.) and the line number in the database are set to be minus for this line and also the default site and warehouse for this Item is not automatically set.
Question: Looks like I've retrieved the values but didn't pass it correctly to the lookup of the field, I don't understand what exactly I missed to make it work normally.
Thanks in advance.
I'm surprised I missed this at first glance.
This line is your problem:
InventJournalTrans_DS.research();
You're researching before you've updated/written the data. I'm not sure why you're researching in the first place, but you have to do one or the other. Write/Update, then research or don't research. The research is where you're losing the ItemId you've input.
In App Maker, I am displaying a table and want to replace table cell data with different text using a data lookup from another table. Assume two tables, Departments and Employees.
Departments is two fields, DeptID and DeptDescription.
Employees is multiple fields including DeptID.
In the table listing for Employees, I would like to replace the DeptID with the DeptDescription. (The page datasource is Employees. I do not want to set up a relationship between the data models.)
I am guessing I want to do some scripting in the onDataLoad event for the table cell label for DeptID. I have this much so far:
app.datasources.Departments.query.filters.DeptID._equals = widget.datasource.item.DeptID;
app.datasources.Departments.newQuery().run();
widget.text = app.datasources.Departments.item.DeptDescription;
I know this is not correct, but am I close?
This answer is untested, but I wanted to present a possible solution that would not require a lot of DB calls, especially ones that make repeated calls to a server script which might consume a lot of processing time when you do line item calls.
Set up a separate datasource under the Department model. Change the default 'Query Builder' to 'Query Script' and add a parameter of type 'list(number)' or 'list(string)', this should match your Primary Key field type. Uncheck the 'auto load' option.
In your 'Query Script' portion enter the following code:
query.filters.Id._in = query.parameters.YourParameter;
return query.run();
Go to your Employees datasource that is supposed to generate your table and find your 'On Load' client script section. In this section enter the following code:
var departmentsDs = app.datasources.YourDepartmentsDs;
departmentsDs.properties.YourParameter = datasource.items.map(function(deptIds) {return deptIds.DeptID;});
departmentDs.load();
Now go the page that contains your table. If you have not already create a label widget do so now. In this label widget for the text binding enter the following:
#datasources.YourDepartmentsDs.loaded && (#datasources.YourDepartmentsDs.items).map(function(Id){return Id.Id}).indexOf(#widget.datasource.item.DeptID) !== -1 ? #datasources.YourDepartmentDs.items[(#datasources.YourDepartmentsDs.items).map(function(Id){return Id.Id}).indexOf(#widget.datasource.item.DeptID)].DeptDescription : 'Unable to retrieve Dept Description'
As stated this is untested and I wrote the code from memory without App Maker in front of me so it may require some additional tweaking. Going with the first option presented by J.G. would also be a very viable solution though. And I apologize but the code formatter does not seem to be working for me.
1 way) Create an aggregate table that joins your tables if you need to bypass using the relations feature. This way you can use sql to join the two tables in the datasource definition
2) if you don't want to make a new table. Change the text from a value binding to "more options"
=getDescription(#datasource.item.DeptId)
and then the code you wrote in a client side script
function getDescription(id){
google.script.run
.withSuccessHandler(function successHandler(result){ return result;})
.withFailureHandler( function failureHandler(e){ console.log(" Failed" +e);})
.queryValue(id);
}
server side script:
function queryValue(id){
var query = app.models.Departments.newQuery();
query.filters.DeptID._equals = id;
var results = query.run();
return results[0]["DeptDescription"];
}
that last line might be results[0].DeptDescription
How do I change the query page size of a calculated model. I have it set to 10 by default but, upon a user searching for records that contain a specific string, I'd like to display all records and remove pagination. is this possible?
The correct way of doing this would be to set the page size to 0 on the client by doing the following (this is assuming you are directly referencing your datasource):
app.datasources.YourDatasource.query.pageSize = 0;
This is the client solution. If you where comparing specific string in your datasource Query Script or through another server script then it would be as follows:
query.limit = 0;
Hope this helps.
I currently have a report that have 9 value prompts items,so far I can only load the prompts with the values that the user can select from, however the desired results should be based on user selection for example if user selected from value prompt1 then only values that are related to value prompt1 should be populated in other value prompts and so on. Your assistance in this regards will be highly appreciated, Thanks in advance.!!!
If I understand correctly, you want ValuePrompt2 to populate after a value is selected in ValuePrompt1 and be filtered by that selection. You want ValuePrompt3 to populate after a value is selected in ValuePrompt2 and be filtered by that selection and the selection in ValuePrompt1. Etc.
Given object relationships that follow this pattern: QueryN : ValuePromptN : ParamN : QueryItemN
You need to set up Param1 as a Cascade Source for ValuePrompt2. Cognos figures out the filtering for this.
You also need to set up Param2 as a Cascade Source for ValuePrompt3. But that won't filter ValuePrompt3 by the selection(s) in ValuePrompt1. To do that, you'll need to make Query3 more specific by adding filters that use Param1 and Param2.
QueryItem1 = ?Param1?
QueryItem2 = ?Param2?
(For clarity, you'll probably want to filter Query2 in a similar manner.)
So when you get to ValuePrompt9, it will be sourced from Query9 and have these filters...
QueryItem1 = ?Param1?
QueryItem2 = ?Param2?
QueryItem3 = ?Param3?
QueryItem4 = ?Param4?
QueryItem5 = ?Param5?
QueryItem6 = ?Param6?
QueryItem7 = ?Param7?
QueryItem8 = ?Param8?
...and its Cascade Source property will be set to Param8.
Consider the design of your queries. A prompt page like you propose may be very slow.
Updated based on new requirement...
If you need to select the values in any order, all of the source queries should have filters to use all of the other parameters and none of the prompts should have the cascade source property set. Then, create a new prompt (PromptNH) for each prompt (PromptN), set its Cascade source property to the related parameter (ParamN), set the Auto-submit property of the source prompt (PromptN) to Yes, and hide the prompt (PromptNH). This forces a reprompt after each selection. Keep in mind that in this scenario the prompt page will quickly filter itself into an unusable state.
Thanks for all the valuable inputs, I only needed to enter a measure in my query so that the filtering can only happen where the is volume in those filters
I have a form where user picks a Item# and gets info for the selected Item. This form got enhanced by adding another filter, using a combobox control, to select a 'warehouse'.
I could use a lookup for the warehouse(the list is huge) to chosse a 'warehouse' but what am trying to do to query warehouse on Item# value and populate into combobox.
Tried to attached a screen shot, unfotunately, the system doesn't let me do it. If I need to put more details, please let me know.
Is it doable?
I would suggest you to do this with a temporary table. Create one in AOT, and declare it as global variable in your form.
When Item (datasource field or design control, choose what's more accurate for you) is modified, just delete table content, and fill it at your needs.
In the control lookup method, call temporary table lookup method, i.e. "static void lookup(TMPTable _tmpTable)". Do a SysTableLookup, with a standard query over TMPtable, but it's important to use QueryBuildDataSource.setCursor(_tmpTable) (I don't remember now where was method setCursor() in Query or QueryRun, search for it a bit).