cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic number conversion to string in object

former_member460045
Participant
0 Kudos

Hello,

my issue is this.

In below coding (simplified), what is the reason that the property "status" is becoming a string?

The oData Field is a Integer.

var iStatus = parseInt(oView.byId("status").getSelectedKey(), 10); //get Status of select

oModel.create(sPath, {
//...
status: iStatus, 
//...
}, fnCallback...);

console.log(oModel.getProperty("status"); --> STRING 

former_member467961
Participant
0 Kudos

Hello Johannes,

if you are unable to edit your question, you can add a new comment with a screenshot of the oData structure and the code where you are reading the value of Status.

Best Regards,

Bopanna

former_member460045
Participant
0 Kudos
onProjectSave: function () {
var oModel = this.getView().getModel();
var oView = this.getView();

var iStatus = parseInt(oView.byId("status").getSelectedKey(), 10);
console.log(typeof iStatus, iStatus); --> number

var oAddon = {
// some other properties
pmtStatus: iStatus,
// some other properties
};

oModel.update("/pmtAddon('" + oObject.pmtId + "')", oAddon, {
		success: function (oData, Response) {
			that._setFragment("Display");
			that._toggleButtons(false);
			console.log(typeof that._getCurrentRecord().statusId);
}
});
getCurrentRecord: function () {
 if (this.getView().getBindingContext()) {
return this.getView().getBindingContext().getObject();
			}
		},









View Entire Topic
former_member467961
Participant
0 Kudos

Hello Johannes,

console.log writes a message to the console by default

please use typeof operator to get the primitive type of the variable:

var status = oModel.getProperty("status"); 
console.log(typeof status);// expected output: "number" in your case
former_member460045
Participant
0 Kudos

Hi,

thats exactly what I did. The data types in my description are identified by typeof operation.

I did'nt mention it and I cannot edit the question anymore.

Best regards Johannes