SAPUI5 dropdown list data binding - sapui5

I'm trying to populate a dropdown list with names of employees fetched from success factors, but I can't get the response to display correctly. I can display the managerId and userId no problem just not the first and last name.
Here is the response:
{
"d": {
"results": [{
"__metadata": {
"uri": "https://apisalesdemo8.successfactors.com:443/odata/v2/EmpJob(seqNumber=1L,startDate=datetime'2010-02-01T00:00:00',userId='spappar1')",
"type": "SFOData.EmpJob"
},
"userId": "spappar1",
"managerId": "rmaxx1",
"employmentNav": {
"__metadata": {
"uri": "https://apisalesdemo8.successfactors.com:443/odata/v2/EmpEmployment(personIdExternal='spappar1',userId='spappar1')",
"type": "SFOData.EmpEmployment"
},
"personNav": {
"__metadata": {
"uri": "https://apisalesdemo8.successfactors.com:443/odata/v2/PerPerson('spappar1')",
"type": "SFOData.PerPerson"
},
"personalInfoNav": {
"results": [{
"__metadata": {
"uri": "https://apisalesdemo8.successfactors.com:443/odata/v2/PerPersonal(personIdExternal='spappar1',startDate=datetime'1990-01-01T00:00:00')",
"type": "SFOData.PerPersonal"
},
"lastName": "Pappar",
"firstName": "Steve"
}]
}
Here is my data binding for the dropdown:
var employeeTemplate = new sap.ui.core.ListItem({
text: "{employeeDropDownModel/employmentNav/personNav/personalInfoNav/results>firstName} {employeeDropDownModel/employmentNav/personNav/personalInfoNav/results>lastName}"
});
sap.ui.getCore().getElementById('employeeId').bindItems("employeeDropDownModel>/d/results", employeeTemplate);
Any help would be awesome, I have tried many different combinations to get the binding to work, but to no avail.

Can you provide a jsbin of the entire UI flow. One thing that strikes me immediately from my experiences is that you are trying a complex binding and your index.html should have the following
**data-sap-ui-xx-bindingSyntax="complex"**
If this does not fix, can you provide a jsbin example?
Thanks and Regards,
Veera

Thanks for the comments and suggestions guys, I tried many different ways:
employeeDropDownModel>/employmentNav/personNav/personalInfoNav/results/firstName
employeeDropDownModel>/employmentNav/personNav/personalInfoNav/results/0/firstName
Neither of thses worked and I do have data-sap-ui-xx-bindingSyntax="complex" in my index.html.
So what I ended up doing was binding the model in the usual way and then just moving the first and last name up in the model to the same level as userId and managerId:
$.each(
this.employeeModel,function(index, value) {
if (value.employmentNav.personNav.personalInfoNav.results.length > 0) {
var firstName = value.employmentNav.personNav.personalInfoNav.results[0].firstName;
var lastName = value.employmentNav.personNav.personalInfoNav.results[0].lastName;
value['firstName'] = firstName;
value['lastName'] = lastName;
} else {
value['firstName'] = '';
value['lastName'] = '';
}
});
This solved my issue pretty well. I'm not sure if this is a very good solution, but it worked for me.
Thanks again

Related

I am Having Issues Accessing My Custom Data In Flutter, How To Access The Features Data in The Data Below

Here is the JSON path need to be edited:
List populars = [
{
"image":
"",
"name": "Single Villa",
"price": "280,000FCFA",
}
]
},
]
I think you're tring to implement your code as Map.
In order to use your JSON format in Dart, you need to make it Map first.
Map map = populars.asMap();
Then you can use it like that:
print(map[key])
try this if you want to get the data inside your created json either ways there are more ways to it.
final getFeatures = populars.map((e)=> e['features']).first;
print(getFeatures[0]['type']);
print(getFeatures[1]['rooms']);
print(getFeatures[2]['toilet']);
print(getFeatures[3]['parlor']);
print(getFeatures[4]['water']);
//Result
Studio
1
1
1
true
I think the issue is in the structure itself,
it should be like this:
{
"name": "Single Villa",
"features": {
"type": "Studio",
"rooms": 1,
"toilet": 1,
"parlor": 1,
"water": true
}
},
then you can use it like this:
final name = populars[index]['name'];
final rooms = populars[index]['features']['rooms'];
...

Prisma, select row from table 1, depending on the latest foreign key in table 2

Apologies for the bad title, struggling to think of another.
Currently, I have 2 tables, publication and publicationStatus.
A publication will looking something like:
{
"id": "ckyil950d00027v2str5ljo7h",
"url_slug": "ckyil950e00037v2s4mqxvaho",
"type": "PEER_REVIEW",
"title": "Intersting review",
"content": "Content is optional at this stage",
"doi": "1093/ajae/aaq063",
"createdBy": "test-user-1",
"createdAt": "2022-01-17T11:12:50.845Z",
"updatedAt": "2022-01-17T11:12:50.847Z",
"publicationStatus": [
{
"status": "LIVE",
"createdAt": "2022-01-19T11:12:50.846Z",
"id": "ckyil950e00047v2sx4urbfte"
},
{
"status": "DRAFT",
"createdAt": "2022-01-17T11:12:50.846Z",
"id": "ckyil950e00047v2sx4urbfth"
}
],
"user": {
"id": "test-user-1",
"firstName": "Test",
"lastName": "User 1"
}
}
Where publication has a 1 to many relationship with publicationStatus.
What I need to do is a find query where it only returns a publication if the latest publicationStatus for that publication, has a status of LIVE.
Any ideas?
Edit:
The closest I could come to is this psuedo code:
await prisma.publication.findFirst({
where: {
id,
publicationStatus: {
where: {
status: 'LIVE'
},
take: 1,
orderBy: {
createdAt: 'desc'
}
},
}
});
This code does not work, but demonstrates a picture of what I'm trying to achieve.
Unfortunately, I don't think it's possible to do what you're hoping directly with a Prisma Query at the moment. I can suggest two possible workarounds though:
Approach 1: Fetch the most recent publicationStatus along with the publication and check the status inside your node application.
This is what the query would look like:
let publication = await prisma.publication.findFirst({
where: {
id
},
include: {
publicationStatus: {
orderBy: {
createdAt: 'desc'
},
take: 1
}
}
});
// check publication.publicationStatus[0].status and handle appropriately
Approach 2: Write a raw SQL query using the queryRaw method.
For a single publication, I think it would be easier to use approach 1. However, if you want to return all LIVE publications (you mentioned this in a comment), the performance characteristics of approach 1 might be undesirable.

Wiremock JsonMatcher or JsonPathMatcher not working

I want to match a request body using Wiremock dotnet. Sample request body
{
"name": "ashutosh",
"age": 33
}
I want to match it with one of the key value combination like either age or name.
I tried the below combinations but nothing seems to match
"Body":{
"Matcher": {
"Name": "JsonPathMatcher",
"Pattern": "$.[?(#.name == 'ashutosh')]"
}
}
"Body":{
"Matcher": {
"Name": "JsonMatcher",
"Pattern": "{ \"age\": 33}"
}
}
Can somebody help me with this? Thanks in advance
Figured out the answer. We need to use double dots instead of one dot I have used in JsonPathMatcher like this:
"Body":{
"Matcher": {
"Name": "JsonPathMatcher",
"Pattern": "$..[?(#.name == 'ashutosh')]"
}
}

LoopBack Relationships

This is my first time dealing with a NoSQL form of database and I'm a little confused about "relationships" in document-oriented databases. I'm using LoopBack & AngularJS.
I have a model page that has many page as it's children (i.e. menu items and submenus).
A page model is as follows:
"properties": {
"name": {
"type": "string",
"required": true
},
"slug": {
"type": "string"
},
"link": {
"type": "string"
},
"createdAt": {
"type": "date",
"required": true
},
"children": {
"type": [
"object"
]
}
},
with
"relations": {
"children": {
"type": "hasMany",
"model": "page",
"foreignKey": "parentId"
}
},
My confusion is that whenever I explore the LoopBack API, and then get the parent pages, I don't see the children property populated. But, doing a get to see the children of a parent (using the parent's id) turns out fine - I can see the parentId populated with it's parent.
My question is if this is normal when dealing with NoSQL/document-oriented databases, or am I doing something wrong?
Thanks a lot!
Sometimes LoopBack queries are getting messy when its come to relationships and parallel queries.
I think this is simply a query issue in LoopBack.
As I realized this is like Parent Page object can have multiple Children page objects.
We can use following query statement to retrieve related parent page and children pages.
app.models.Page.find({
where: {
parentId : 'yourPageId'
},
include: {
relation: 'Children'
}
}, function (err, pages) {
if (err) {
cb(err);
} else {
console.log("you will get related children pages alone with parent page")
cb(null, pages);
}
});
Hope this will work...!!
I believe you might be missing the other direction of the relationship.
You can do a belongsTo relation in the children to specify that it belongs to a parent.
That should enable you to see both directions' methods in the explorer.
Also, the foreingKey parentId should be set on the children, not on the parent. I.e. leave foreignKey empty on the parent relations definition, and instead use it on the children relations definition.
So on one hand, in the model you will have inside the relations field:
"children": {
"type": "hasMany",
"model": "page",
"foreignKey": ""
},
And also
"parent": {
"type": "belongsTo",
"model": "page",
"foreignKey": "parentId"
},
plus any other relations you have.
I have tested this and it works, although I have used two different models for the relation instead of only one.
I.e. I use
ModelA hasMany ModelB and ModelB belongsTo ModelA
instead of
ModelA hasMany ModelA and ModelA belongsTo ModelA
In mongoose when you want to get the page's "children" populated you need to specifically ask for it using:
Pages.find({})
.populate('children')
.exec(function(err, pages){
//..
})
Looking on LoopBack's page (http://loopback.io/doc/en/lb2/Querying-related-models.html) there is something similar called "include", you should try doing:
Page.find({include:'children'}, function() {
//...
});
Let me know if that worked!

SAPUI5 - create a JSONModel from Ajax response

I'm trying to build a SAPUI5 application using JSON model.
I want to add 2 dropdown select menus, so that the second one fills in depending on the current selection of the first one.
I tried to get it done, but stucked at the very beginning.
This is what I get from Ajax (the object itself is passed from the server):
var data = {
"firm1":["firm1project1","firm1project2","firm1project3"],
"firm2":["firm2project1","firm2project2","firm2project3"],
"firm3":["firm3project1","firm3project2","firm3project3"],
"firm4":["firm4project1","firm4project2","firm4project3"]
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(data);
sap.ui.getCore().setModel(oModel);
The first menu should be the list of firms and the second one - is the selected firm's projects. And now I have no idea how to bind the data to the controls the right way.
Thank you.
EDIT:
According to what I've read in the developer's guide, the data that should appear in different controls is contained under fixed keys (as shown in "Aggregation Data Binding in a Simple Application" part of the page that I linked above), so it would be possible to just write something like:
var oListItemTemplate = new sap.ui.commons.ListItem("ListItemTemplate", {
text : "{firm}",
});
and for the projects:
var oListItemTemplate = new sap.ui.commons.ListItem("ListItemTemplate", {
text : "{firm/project}",
});
But in my case there is no firm key. My ListItems for the firm selection menu are keys, not values. And ListItems for the project selection menu are in an array, not just separate values under fixed keys.
So, is there a way or to bind somehow the data I have in its current form to controls, or how the data should look like to be useful for binding?
your data looks better like the following, the data binding JSON objects are with keys. And there are two data models needed for two dropdown boxes, multi data model binding should be used. I did a example at JSBin which fulfills your requirements, you can have a look and get some thoughts.
{
"firms": [
{
"name": "firm1",
"projects": [
{
"name": "firm1project1"
},
{
"name": "firm1project2"
},
{
"name": "firm1project3"
}
]
},
{
"name": "firm2",
"projects": [
{
"name": "firm2project1"
},
{
"name": "firm2project2"
},
{
"name": "firm2project3"
}
]
},
{
"name": "firm3",
"projects": [
{
"name": "firm3project1"
},
{
"name": "firm3project2"
},
{
"name": "firm3project3"
}
]
},
{
"name": "firm4",
"projects": [
{
"name": "firm4project1"
},
{
"name": "firm4project2"
},
{
"name": "firm4project3"
}
]
}
]
}