Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3323

XS ODATA POST call- Syntax error at position 0, Edm.DateTime

$
0
0

Hi Experts,

I am getting the below error when i am trying to call a ODATA Create service with a field with TIMESTAMP as data type and it is also one of the primary key.

 

The following problem occurred: HTTP request failed400,Bad Request,{ "error": { "code": "", "message": { "lang": "en-US", "value": "Syntax error at position 0."}}} 

 

The value for the field is always current_utctimestamp. But as it is one of the primary key it is required to pass this value from UI5 application else we get a different error as "The serialized resource has an missing value for member 'From".

 

 

 

Now we tried removing the timestamp field as primary key which removes the constraint of passing the value from UI5 application and the service just worked fine and inserted the record in the table.

 

Please find the code below for your reference

PROCEDURE CODE:

 

PROCEDURE "ABC_XYZ"."ABC_XYZ_PRJ.PROCEDURE::RT_CustomerDevice" (IN ip "ABC_XYZ"."ABC_XYZ_PRJ.TABLES.RELATIONSHIP::RT_CustomerDevice",

  OUT op "ABC_XYZ"."ABC_XYZ_PRJ.STRUCTURES::Error")

 

 

LANGUAGE SQLSCRIPT

SQL SECURITY INVOKER AS

--DEFAULT SCHEMA <default_schema_name>

--READS SQL DATA AS

 

ls_UserName   VARCHAR(30);

ls_DeviceType VARCHAR(30) ;

ls_DeviceId   VARCHAR(30) ;

ls_From       timestamp;

 

BEGIN

/*****************************

Write your procedure logic

*****************************/

   

IF :ls_UserName= ''    THEN

 

--'' OR :ls_DeviceType = '' OR ls_DeviceId= '' OR ls_From = ''

 

op    =  select  400 as http_status_code,

'pass all the values' as error_message,

  '' as detail

from dummy;  

ELSE     

 

SELECT "UserName", "DeviceType", "DeviceId","From"

INTO ls_UserName, ls_deviceType, ls_deviceId, ls_From

FROM :ip;

 

 

INSERT INTO "ABC_XYZ"."ABC_XYZ_PRJ.TABLES.RELATIONSHIP::RT_CustomerDevice"

VALUES (:ls_UserName,:ls_deviceType,:ls_deviceId,:ls_From,'2099-12-31 23:59:59.9999999');

 

END IF;

END;

 

==================================================================================================================

SERVICE:

 

service {

 

 

"ABC_XYZ"."ABC_XYZ_PRJ.TABLES.RELATIONSHIP::RT_CustomerDevice" as "Device"

create using "ABC_XYZ_PRJ.PROCEDURE::RT_CustomerDevice"

;

}

 

From UI5

addDevice: function(){

 

    var date = new Date();

    var dateformat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern: "yyyy-MM-dd\'T\'HH:mm:ss"});

    var formatted  = dateformat.format( date,true);

 

    var oEntry = {};

    oEntry.UserName = "loggedInUser";

    oEntry.DeviceType = "DT123";

    oEntry.DeviceId = "deviceId1234";

    oEntry.From = formatted;//2016-03-24T21:46:22

 

    var ServiceUrl =  "https://xxxxx.xxxx.com/xxxxxxx/SERVICES/Srv_CustomerDeviceRegistration.xsodata";

    var odataModel = new sap.ui.model.odata.ODataModel(ServiceUrl,{json: true});

        odataModel.create("/Device", oEntry, null, function(){

                alert("Device Resigtration successful");

            }, function(oError){

                   if(oError.response.statusCode === 500 ||

                    oError.response.statusCode === 400){

                        var errorRes =   JSON.parse(oError.response.body);

                        sap.m.MessageBox.alert(errorRes.error.message.value);

                        return;

                    }

                    else{

           

                        sap.m.MessageBox.alert(oError.response.statusText);

                        return;

                    }

            });

}

 

Not sure that problem with datetime format which in the request or issue in the service itself.

 

Thanks,

Venugopal

 


Viewing all articles
Browse latest Browse all 3323

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>