This topic is locked

How to update details table while editing master record

12/9/2014 12:41:07 PM
PHPRunner Tips and Tricks
admin

Lets imagine you editing master and details records together and need to update all details records with some value from the master record.
In this example we update prices of all details records with the price from the master record. While this example is completely artificial there are many cases when it might useful. Here is how it works in live application.
---------------------------------------------------------------------------------------------------------------------------------


---------------------------------------------------------------------------------------------------------------------------------
To implement this add the following code to Javascript OnLoad event of the master record Edit page.

var ctrl = Runner.getControl(pageid, 'Price');

ctrl.on('keyup', function(e){

$("[id^=value_Price]").val(this.getValue());

});


In this example field name in both master and details record in Price. If your master record control is a dropdown box you need to use change event.

var ctrl = Runner.getControl(pageid, 'Price');

ctrl.on('change', function(e){

$("[id^=value_Price]").val(this.getValue());

});
A
Anapolis 12/9/2014

I love this kind of Tutorial. I can use things like this. In fact, more tutorials on Javascript.
(I raised a question here earlier but 15 minutes later I found my answer. So, I deleted the question!)
Again, this How to update details table while editing master record is very useful! Thank you!

P
pmorenoc07 12/9/2014

Very helpful thank, solved my problem..

M
mroman98 12/13/2014

How about updating only the last detail record?...

How would you do that?
Regards,

Manuel Roman

admin 12/14/2014

Manuel Roman,
try this:

var ctrl = Runner.getControl(pageid, 'Price');

ctrl.on('keyup', function(e){

$("[id^=value_Price]").last().val(this.getValue());

});


The difference is in the use of last() jQuery function:

http://api.jquery.com/last/

J
jackwood 6/1/2016

But, How do if I update master table while editing Details record.
For Example, I Input ProductPrice X Qty in Detail Table and Sums updated to Master Table ?
Thankyou.

J
jianwong 1/28/2018



Lets imagine you editing master and details records together and need to update all details records with some value from the master record.
In this example we update prices of all details records with the price from the master record. While this example is completely artificial there are many cases when it might useful. Here is how it works in live application.
---------------------------------------------------------------------------------------------------------------------------------


---------------------------------------------------------------------------------------------------------------------------------
To implement this add the following code to Javascript OnLoad event of the master record Edit page.

var ctrl = Runner.getControl(pageid, 'Price');

ctrl.on('keyup', function(e){

$("[id^=value_Price]").val(this.getValue());

});


In this example field name in both master and details record in Price. If your master record control is a dropdown box you need to use change event.

var ctrl = Runner.getControl(pageid, 'Price');

ctrl.on('change', function(e){

$("[id^=value_Price]").val(this.getValue());

});



Sergey
I tried the second sample scripts on my project, however, detail record does not update, just remains blank, after having selected value from the dropdown in master record control. What have I missed? I'm on built 29967. Please advise.

emendoza 2/6/2018

@jian, I recommend sending screenshots or a video to understand your bug