Select data binding in SAPU15 - components

I read the documentation https://sapui5.hana.ondemand.com/#/api/sap.m.Select and tried to do a small example. I created my value in my function onInit of my controller:
var oData = {
"SelectedProduct": "test1",
"ProductCollection": [
{
"ProductId": "test1",
"Name": "test 1"
},
{
"ProductId": "test2",
"Name": "test 2"
},
{
"ProductId": "test3",
"Name": "test 3"
}
]
};
var oModel = new JSONModel(oData);
this.getView().setModel(oModel, "myTest");
I want that my selectedProduct default value is test1 so I init it to test1.
In my xml file, i created my selector as following:
<Select
id="idSelect"
forceSelection="false"
selectedKey="{myTest>/SelectedProduct}"
change="_change"
items="{
path: 'myTest>/ProductCollection'
}">
<core:Item key="{myTest>/SelectedProduct}" text="{myTest>Name}" />
</Select>
So, everytime i change the value, my following code is made:
_change: function () {
console.log("_changeAblauf");
console.log(this.getView().byId("idAblaufbriefeSelect").getSelectedItem());
console.log(this.getView().byId("idAblaufbriefeSelect").getName());
},
My issue is that the print always display the content of my SelectedProduct from oData and not from the selector..
Why it don't take the value from the selector and how can i read my new value of the selector ?

In the key property of the Item you should bind myTest>ProductId: this value will populate your model SelectedProduct property every time the change event will be fired.

Related

Acumatica - Updating User-Defined Field 'View' Error

I am trying to update a Custom Attribute on the Contact entity. Here is the structure for the request body (which works to update regular fields when 'custom' is not included):
{
"ContactID": {
"value" : {{record.ContactID.value}}
},
"custom" : {
"Document":
{
"AttributeEXPORTEDMC" :
{
"type": "Checkbox",
"value": "True"
}
}
}
}
Getting this error: 'An error has occurred.","exceptionMessage":"view Document is not found","exceptionType":"System.InvalidOperationException","stackTrace":" at PX.Api.ContractBased.EntityExportContextBuilder.EnsureCustomField(CustomField customField, String[] views)\r\n at System.Monads.MaybeIEnumerable.Do[TSource](IEnumerable`1 source,'.
The documentation saying that the view will always be 'Document' for user defined fields.
'For any user-defined field, the view name is Document'
Field/View Name Documentation
From: https://help-2020r1.acumatica.com/(W(28))/Help?ScreenId=ShowWiki&pageid=bd0d8a36-b00b-44c8-bdcd-b2b4e4c86fd0
[Update]
Had to first create a UDF. Here is the working version for this case (v2 API):
{
"ContactID": {
"value": {{record.ContactID.value}}
},
"custom": {
"Contact": {
"AttributeEXPORTEDMC": {
"type": "CustomBooleanField",
"value": true
}
}
}
}
You can add a UDF to the endpoint as such and modify it like any other field

jsonapi-serializer overwrites existing "links" attribute

I use an API that returns a response with the following structure:
{
"data": [
{
"id": "id-1",
"type": "objectType",
"attributes": { ... },
"links":
"linksDataAndMetadate": {...}
}, ...
],
"links":
"thisLink": "some url",
"thatLink": "another url"
}
We use jsonapi-serializer package in our code base for serialization/deseiralization, but when I use it to deserialize the response, the outer links part (the ones that includes "thisLink" and "thatLink") overwrites the "links" field inside the object attributes. Is there a way to use the package so that it will have a different behavior?

Logic App : Finding element in Json Object array (like XPath fr XML)

In my logic app, I have a JSON object (parsed from an API response) and it contains an object array.
How can I find a specific element based on attribute values... Example below where I want to find the (first) active one
{
"MyList" : [
{
"Descrip" : "This is the first item",
"IsActive" : "N"
},
{
"Descrip" : "This is the second item",
"IsActive" : "N"
},
{
"Descrip" : "This is the third item",
"IsActive" : "Y"
}
]
}
Well... The answer is in plain sight ... There's a FILTER ARRAY action, which works on a JSON Object (from PARSE JSON action).. couple this with an #first() expression will give the desired outcome.
You can use the Parse JSON Task to parse your JSON and a Condition to filter for the IsActive attribute:
Use the following Schema to parse the JSON:
{
"type": "object",
"properties": {
"MyList": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Descrip": {
"type": "string"
},
"IsActive": {
"type": "string"
}
},
"required": [
"Descrip",
"IsActive"
]
}
}
}
}
Here how it looks like (I included the sample data you provided to test it):
Then you can add the Condition:
And perform whatever action you want within the If true section.

Angular formly: calculate value of one field based on other fields input

json configuration:
{
"moduleconfigs": {
"create": [
{
"key": "Committed",
"type": "horizontalInput",
"templateOptions": {
"label": "Committed"
}
},
{
"key": "Uncommitted",
"type": "horizontalInput",
"templateOptions": {
"label": "Uncommitted"
}
},
{
"key": "Line",
"type": "horizontalInput",
"templateOptions": {
"label": "Line"
}
},{
"key": "Total",
"type": "horizontalInput",
"templateOptions": {
"label": "Total"
},
"expressionProperties":{
"value": function($viewValue, $modelValue, scope){
return scope.model.lineFill+scope.model.uncommitedBPD+scope.model.commitedBPD;
}
}
}
]
}
}
html:
<form>
<formly-for model="vm.myModel" fields="vm.myFields"></formly-form> </form>
I am new to angular formly. I am creating form using angular formly json. Total field should display sum of values provided in Committed+Uncommitted+Line fields. i am using expressionProperties but is not working.
I'm guessing you've moved on from this issue... however...
You are doing two things wrong.
First (1): They key value in the formly field configuration object is setting the value by that name on the model.
So your first field configuration object is:
{
"key": "Committed",
"type": "horizontalInput",
"templateOptions": {
"label": "Committed"
}
},
Then later you try to access that value using the key commitedBPDso you'll always get undefined.
Basically formly is setting the value input in that field on the model object with the key of Committed you need to change the key to match.
Second (2): I could be wrong but I don't think you can use an expression property to set the value like that. Formly will automatically respect value changes on the model so you're better off putting on onChange on the other formly field configuration objects that does the parsing and addition something like this:
{
"key": "Committed",
"type": "horizontalInput",
"templateOptions": {
"label": "Committed"
"onChange": addTotal
}
}...
function addTotal() {
//You have access to the model here because it's in your controller
// NOTE: the parseInput function you'll have to write yourself
vm.model.Total = parseInput(vm.model.Committed) + ...
}
All in all your biggest problem is trying to access the values from the model object with the wrong key
Yes, updating the model does not change form.input.value
The only way I've found is like this:
item.fieldGroup['Import'].formControl.setValue(333.33)

Aggregation in arangodb using AQL

I'm attempting a fairly basic task in arangodb, using the SUM() aggregate function.
Here is a working query which returns the right data (though not yet aggregated):
FOR m IN pkg_spp_RegMem
FILTER m.memberId == "40289"
COLLECT member = m.memberId INTO g
RETURN { "memberId" : member, "amount" : g[*].m[*].items }
This returns the following results:
[
{
"memberId": "40289",
"amount": [
[
{
"amount": 50,
"description": "some description"
}
],
[
{
"amount": 50,
"description": "some description"
},
{
"amount": 500,
"description": "some description"
},
{
"amount": 0,
"description": "some description"
}
],
[
{
"amount": 0,
"description": "some description"
},
]
]
}
]
I am using Collect to group the results because a given memberId may have multiple'RegMem' objects. As you can see from the query/results, each object has a list of smaller objects called 'items', with each item having an amount and a description.
I want to SUM() the amounts by member. However, adjusting the query like this does not work:
FOR m IN pkg_spp_RegMem
FILTER m.memberId == "40289"
COLLECT member = m.memberId INTO g
RETURN { "memberId" : member, "amount" : SUM(g[*].m[*].items[*].amount) }
It returns 0 because it apparently can't find a field in the expanded items list called amount.
Looking at the results I can sort of understand why: the results are being returned such that items is actually a list, of lists of objects with amount/description. But I don't understand how to reference or expand the un-named list correctly to return the amount field values for the SUM() function.
Ideally the query should return the memberId and total amount, one row per member such that I can remove the filter and execute for all members.
Many thanks in advance if you can help!
Martin
PS I've worked through the AQL tutorial on the arangodb website and checked out the manual but what would really help me is loads more example queries to look through. If anyone knows of a resource like that or wants to share some of their own, 'much obliged. Cheers!
Edited: Misread the question the first time. The first one can be seen in theedit history, as it also contains some hints:
I replicated your data by creating some documents in this format (and some with only one item):
{
"memberId": "40289",
"items": [
{
"amount": 50,
"description": "some description"
},
{
"amount": 500,
"description": "some description"
}
]
}
Based on some of those types of documents, your non-summarized query should indeed be looking like this:
FOR m IN pkg_spp_RegMem
FILTER m.memberId == "40289"
COLLECT member = m.memberId INTO g
RETURN { "memberId" : member, "amount" : g[*].m[*].items }
The data returned:
[
{
"memberId": "40289",
"amount": [
[
{
"amount": 50,
"description": "some description"
},
{
"amount": 0,
"description": "some description"
}
],
[
{
"amount": 50,
"description": "some description"
},
{
"amount": 0,
"description": "some description"
}
],
[
{
"amount": 50,
"description": "some description"
}
],
[
{
"amount": 50,
"description": "some description"
},
{
"amount": 500,
"description": "some description"
}
],
[
{
"amount": 0,
"description": "some description"
}
],
[
{
"amount": 50,
"description": "some description"
},
{
"amount": 500,
"description": "some description"
}
]
]
}
]
Based on the non summarized version, you need to loop through the items of the groups that have been generated by the collect function and do your SUM() there.
In order to be able to SUM the items you must FLATTEN() them into a single list, before summarizing them.
FOR m IN pkg_spp_RegMem
FILTER m.memberId == "40289"
COLLECT member = m.memberId INTO g
RETURN { "memberId" : member, "amount" : SUM(
FLATTEN(
(
FOR r in g[*].m[*].items
RETURN r[*].amount
)
)
)
}
This results in:
[
{
"memberId": "40289",
"amount": 1250
}
]

Resources