Let's follow up this discussion at the Neptune Community

(this forum will be kept in read-only mode)

Set a value in a bound Model Source

OK.  New to this, so hopefully this is an easy question.


I am in oPageDetail, which has Model Source = IS_CARTS.


IS_CARTS is a structure which has a field called DECISION


When I click a button with Title 'Approve', I want to set IS_CARTS.DECISION with the value in action (below).


var action = this.getProperty("text"); //works


I want to do this with Javascript, without using AJAX call.


I figure modeloPageDetail. and  Set is involved in some way, but I can't quite get it.


I have tried a bunch of stuff, but am wasting time.  I know I could do this other ways, but I need to know how to set a structure.field from Javascript anyway.


Thanks,


Tim




Hi Tim,


Thank you for posting the question.

You can modify the data of IS-CARTS-DECISION by changing the model source directly using JavaScript. Please see the following code example to store the value of the variable acton to IS-CARTS-DECISION:


var action = this.getProperty("text");
modeloPageDetail.oData.DECISION = action;



1 person likes this

Thanks Nicolay


Oddly, this was one of the things i tried, but my dialog did not show the result, so I dismissed it.


What I have now discovered is that the value is updated in IS_CARTS, but the NAD binding of that value to a Dialog Title does not display until after I push a button on that dialog.


Specifically, I have a shopping cart Detail Screen. on Press of Approve button


// Get Button Pressed

var action = this.getProperty("text");


// Copy button Title to Cart Decision

modeldiaApprove.oData.DECISION = action;


// Open the dialog to enter comments and submit

diaApprove.open();


Then on Dialog diaApprove,  I have bound (in the Designer) Dialog Title = {IS_CARTS-DECISION}.


What I find is the programatically set Dialog Title does not display when the Dialog Opens, but does appear After I Enter Something in Dialogpress a button on the dialog.


Any ideas?


Thanks,


Tim


P.S.  Not sure this is relevant, but I initially set the IS_CARTS structure from the MasterList (IT_CARTS) using MasterList itemPress code:  modeldiaApprove.setData(context.getObject());

P.S.  I think what I am looking for is Two-Way binding?

Hi Tim,


Thank you for the detailed description.

Please note that for the sap.m.Dialog title of the control diaApprove to be displayed accordingly after updating the model source the binding has to be refreshed.


I would recommend implementing the following press event on the Approve button control:

 

// Get Button Pressed
var action = this.getText();

// Copy button Title to Cart Decision
modeldiaApprove.oData.DECISION = action;

// Refresh Binding
modeldiaApprove.refresh();

// Open the dialog to enter comments and submit
diaApprove.open();

   

Login or Signup to post a comment