I work on a SAPUI5 application (in Web IDE) which creates an interaction in Hybris Marketing. Therefore I use OData service CUAN_IMPORT_SRV. I already tried it with a simple Postman request and it worked fine. The interaction was created in Hybris Marketing.
The example JSON body for upload looks like this (oriented by Call OData Service):
{
"Id" : "",
"Timestamp" : "/Date(1506014140593)/",
"UserName" : "UNAME",
"SourceSystemId" : "ANY",
"Interactions" : [
{
"Key" : "",
"CampaignId" : "",
"CommunicationMedium" : "BUSINESS_DOCUMENT",
"ContactId" : "005056966DBE1EE4B299CD12B99F60C4",
"ContactIdOrigin" : "SAP_HYBRIS_MKT_IC",
"ContentData" : "First Event",
"ContentTitle" : "",
"InitiativeId" : "100001622",
"InitiativeVersion" : 0,
"InteractionType" : "CRM_ACTIVITY",
"IsAnonymous" : false,
"MarketingOrchestrationId" : 0,
"Quantifier" : 1,
"Timestamp" : "/Date(1506014140283)/"
}
]
}
It shall not be discussed if the data makes sense or not. It's right now just a test case. In my SAPUI5 application I started writing a simple function which shall handle the data upload. I oriented on this topic.
This is my function:
onPressScan: function() {
sap.ndc.BarcodeScanner.scan(
function(mResult) {
if (!mResult.cancelled) {
// begin POST Interaction with OData
var oModel = new sap.ui.model.odata.v2.ODataModel("https://host:port/sap/opu/odata/sap/CUAN_IMPORT_SRV/", true, "UNAME", "PASSWORD");
oModel.setHeaders({
"X-CSRF-Token" : "Fetch"
});
var jsonString = '{ "Id" : "", "Timestamp" : "/Date(1506014140591)/", "UserName" : "UNAME", "SourceSystemId" : "ANY", "Interactions" : [ ' +
'{ "Key" : "" , "CampaignId" : "" , "CommunicationMedium" : "BUSINESS_DOCUMENT" , "ContactId" : "005056966DBE1EE4B299CD12B99F60D4" ' +
', "ContactIdOrigin" : "SAP_HYBRIS_MKT_IC" , "ContentData" : "Try from Scanner App", "ContentTitle" : "Scan", "InitiativeId" : "100001622" ' +
', "InitiativeVersion" : 0, "InteractionType" : "CRM_ACTIVITY", "IsAnonymous" : false, "MarketingOrchestrationId" : 0, "Quantifier" : 1, "Timestamp" : "/Date(1506014140281)/" }]}';
var json = JSON.parse(jsonString);
// get X-CSRF-Token for POST request
oModel.read("/$metadata", null, null, true, function(oData, oResponse) {
var xcsrfToken = oResponse.headers["x-csrf-token"];
oModel.setHeaders({
"X-CSRF-Token" : xcsrfToken,
"Content-Type" : "application/json"
});
// POST interaction to yMarketing
oModel.create("/ImportHeaders", json, null, function() {
alert("Create successful");
}, function(){
alert("Create failed");
});
}, function() {
alert("Read failed");
});
}}, function(Error) {
sap.m.MessageBox.error("Scanning failed due to following error: " + Error, {
title: "Error while scanning"
});
}
);
}
When I try the application I get the following error:
When declaring the OData Model I use a correct system UNAME and PASSWORD for reading and writing. What do I do wrong?
Any hints well appreciated!
Click Chrome Icon > Options > Add this behind your target path:
--disable-web-security --user-data-dir
Related
In OData Model V2, I'm struggling by reading the odata of my mocked server:
I want to get access to the child entity which is associated with a Parent entity.
From Open_Station I can navigate to_Order_Header:
[{
"results": [
{
"__metadata": {
"id": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
"uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
"type": "cds_zui_check_dialog.Open_StationType"
},
"Station": "CHE1",
"Task": "5246",
"to_Order_Header": {
"__deferred": {
"uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"
}
}
}
]
}
]
And from to_Order_Header, I can navigate to Order_Item or Stock:
[{
"__metadata" : {
"id" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
"type" : "cds_zui_check_dialog.Order_HeaderType"
},
"OrderNumber" : "00000000100000000853",
"Station" : "CHE1",
"OrderIndicator" : "",
"to_Order_Items" : {
"__deferred" : {
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Order_Items"
}
},
"to_Stock" : {
"__deferred" : {
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Stock"
}
}
]
In my controller, I have a metho ReadOdata read data like this:
ReadOdata: function()
{
var oModel = new sap.ui.model.odata.v2.ODataModel("http://WebService");
return new Promise(function(resolve, reject)
{
oModel.read("Open_Station(Station='CHE1',Task='5246')/to_Order_Header", {
success : function (data) {
resolve(data);
},
error: function (oError) {
reject(oError);
}
});
});
},
I always get a failure like this:
Request failed with status code 404: GET Open_Station(Station='CHE1',Task='5246')/to_Order_Header
- [{"code":404,"message":"Resource not found","persistent":false,"targets":["/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"],"type":"Error"}]
sap.ui.model.odata.ODataMessageParser
I think the way I want to read the associated entity is wrong. Please help me.
I found a solution. It was a failure in the annotation of the Path:
Instead of writing:
oModel.read("**to_Open_Station**(Station='CHE1',Task='5246')/to_Order_Header", {
I was writing:
oModel.read("*Open_Station*(Station='CHE1',Task='5246')/to_Order_Header", {
In the MetaData, the NavigationProperty was called to_Open_Station.
Here is my database entry structure, it has a nested document called friends, I want to compare two different _id's friends list in dart using mongo_dart
{
"_id" : ObjectId("60ae06074e162995281b4666"),
"email" : "one#one.com",
"emailverified" : false,
"username" : "one#one.com",
"displayName" : "complete n00b",
"phonenumber" : "",
"dob" : "",
"points" : 0,
"friends" : [
{
"username" : "three#one.com",
"sent" : ISODate("2021-05-26T10:01:30.616Z")
},
{
"username" : "six#one.com",
"sent" : ISODate("2021-05-26T10:43:16.822Z")
}
]
}
Here is my code, but I am not getting any returns
Future<Map> commonFriends(store, myObjectId, theirObjectId) async {
var commonList = await store.aggregate([
{
'\$project': {
'friends': 1,
'commonToBoth': {
'\$setIntersection': [
{'_id': myObjectId, 'friends': '\$username'},
{'_id': theirObjectId, 'friends': '\$username'}
]
},
}
}
]);
return commonList;
}
I am getting an error from db.dart which is apart of mongo_dart package. The error is "Exception has occurred.
Map (4 items)"
I have this database on Firebase:
{
"issues" : {
"-L04771_EjrLlv5u1-GU" : {
"issue" : "Test insert 1",
"last_edit" : "d8QICgTG5xR20RBzAXfzfu8gLgw2",
"owner" : "d8QICgTG5xR20RBzAXfzfu8gLgw2",
"owner_email" : "example1#gmail.com",
"status" : 1,
"url" : "http://www.example.com/example.html"
},
"-L047pIoqxkj4saaTYyQ" : {
"issue" : "Test insert 2",
"last_edit" : "d8QICgTG5xR20RBzAXfzfu8gLgw2",
"owner" : "d8QICgTG5xR20RBzAXfzfu8gLgw2",
"owner_email" : "example2#gmail.com",
"status" : 1,
"url" : "http://www.example.com/example.html"
}
}
}
I have to extract only those who have owner_email "example1#gmail.com".
Is possible?
You're probably looking for Firebase Queries and especially the equalTo-Query.
Your code would be something like this:
// Find all issues with owner_email = example1#gmail.com
var ref = firebase.database().ref("issues");
ref.orderByChild("owner_email").equalTo("example1#gmail.com").on("value", function(snapshot) {
// Loops through the matching issues
snapshot.forEach(function(child) {
console.log(child.key);
});
});
i have a OData model i need to make batch read request
the model is ctreated as below
this.oModel = new sap.ui.model.odata.ODataModel(sURI,{
json : true,
user : "<username>",
password : "<password>",
useBatch : true
});
The filter and batch requests are created as below
var allfilters = [new sap.ui.model.Filter({
path:'filter1',
operator : sap.ui.model.FilterOperator.EQ,
value1 : this.filter1value
}),
new sap.ui.model.Filter({
path:'DateField',
operator : sap.ui.model.FilterOperator.EQ,
value1 : 'SCHED'
}),
new sap.ui.model.Filter({
path:'StartDate',
operator : sap.ui.model.FilterOperator.EQ,
value1 : oDateFormat.format(this.startDate.toDate())
}),
new sap.ui.model.Filter({
path:'EndDate',
operator : sap.ui.model.FilterOperator.EQ,
value1 : oDateFormat.format(this.endDate.toDate())
})];
var batchrequest = this.oModel.createBatchOperation('/ReadEntitySet','GET',{
filters : allfilters
});
this.oModel.addBatchReadOperations([batchrequest]);
this.oModel.submitBatch(this._gotData.bind(this),function(err){
console.log(err);
});
When we debug the ABAP code we are not getting the filters.
filters is not a valid property for the oData parameter of createBatchOperation. You can achieve this either by appending the $filter directly to your path, or you can use v2 ODataModel, an example as follows...
this.oModel = new sap.ui.model.odata.v2.ODataModel(sURI,{
json : true,
user : "<username>",
password : "<password>",
useBatch : true
});
this.oModel.setDeferredGroups(["myDeferredGroup"]);
this.oModel.read("/ReadEntitySet",{
groupId: "myDeferredGroup",
filters: allFilters,
success: this._gotData.bind(this),
error : function(err){
console.log(err);
}
});
this.oModel.submitChanges({
groupId: "myDeferredGroup",
success: function(oData){
},
error : function(err){
}
});
Is it possible to create Salesreceipt without product/service value through QBO API? I have tried through API but it's not reflecting rate value and storing description value only.
If I remove ItemRef attribute(in request body) then it's reflecting rate and amount values and it's assigning some default and random product/service.
It is possible directly in QBO UI.
Request body where only description value storing:
{
"TxnDate" : "2016-05-27",
"Line" : [ {
"Amount" : 2222.00,
"Description" : "hi chk",
"DetailType" : "ItemReceiptLineDetail",
"ItemReceiptLineDetail" : {
"ItemRef" : { },
"Qty" : 1,
"UnitPrice" : 2222
} }
],
"CustomerRef" : {
"value" : "67"
},
"CustomerMemo" : {
"value" : "Thanks for your business! We appreciate referrals!"
},
"TotalAmt": 2222.00,
"PrivateNote" : "",
"CustomField" : [ {
"DefinitionId" : "1",
"Type" : "StringType",
"StringValue" : ""
} ]
}
Request body where default product/service assigning:
{
"TxnDate" : "2016-05-27",
"Line" : [ {
"Amount" : 2222.00,
"Description" : "hi chk",
"DetailType" : "ItemReceiptLineDetail",
"ItemReceiptLineDetail" : {
"Qty" : 1,
"UnitPrice" : 2222
} }
],
"CustomerRef" : {
"value" : "67"
},
"CustomerMemo" : {
"value" : "Thanks for your business! We appreciate referrals!"
},
"TotalAmt": 2222.00,
"PrivateNote" : "",
"CustomField" : [ {
"DefinitionId" : "1",
"Type" : "StringType",
"StringValue" : ""
} ]
}
No.
QuickBooks Online does not support this.