Update a field value when another field is edited


^bump^ :smiley:

I think the new actions on your junction model could work.
Iā€™m using an action to update a date/time field when another field is changed on the same mode.

I have one action, which updates a field to the current date. Ā Thereā€™s a specific option for that.

In your case, I think youā€™ll need a snippet, since your wanting to update one model field with a value from another model field.

Iā€™ve seen samples around that do that, but Iā€™m still new to Skuid so I can help with specifics. Ā Iā€™m just sure thereā€™s lots of {} in itā€¦ :smiley:

Seth

I tend to agree with Seth. Ā This is not possible just using the action framework - in a table as you have.Ā 

If you were able to get the process item in a model (by itself) Ā then you could add a new row to the junction object table and pass the default value for sequence to it. Ā I believe this would have to be a two step process. Ā 1 being select the process - and filter the process model down to just that item, Ā and 2 populate the row in the junction object table.Ā 

I also donā€™t think you are going to be able to have this function well in the ā€œedit existingā€ scenario without some javascript.Ā 

I was suspecting this. Basically think that I need to setup a listening function. Not even sure thatā€™s what it is called.

On change, take the id of the reference and update a model condition with it in order to get access the desired data. Then I can update the second field.

Itā€™s the listening part that Iā€™m new to. Once I have the Id, then Iā€™m good to go.

We got a similar thing working from this post - check out the first half of Benā€™s answer. Admittedly I havenā€™t tried running this on a reference field, but what it basically does is:

When ā€˜this_field__cā€™ is updated, then get another value from the same row, and populate it into ā€˜second__field__cā€™

var params = arguments[0], <br>$ = skuid.$,<br>updates = params.updates,<br>defaultSequence; <br>//if the process reference field is updated by the user, <br>//then get the value of default sequence field for that row<br>//check that field is being pulled into the Process Model in your page <br>if ('Process__c' in updates) {<br>&nbsp; &nbsp;&nbsp;defaultSequence = params.row.defaultSequence__c;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; if (defaultSequence) {<br>&nbsp; &nbsp; &nbsp; &nbsp; params.model.updateRow(params.row,'defaultSequence__c',defaultSequence); &nbsp;<br>&nbsp;&nbsp;&nbsp;}


See if you have any joy with that!

 

this also needs you to create an action on the model - when model is updated, then run the snippet.

Also, as it is a reference field, this line:

params.row.defaultSequence__c;

might need to be more like:

params.row.Process__r.defaultSequence__c;

Greg. You are the man! That was exactly what I was looking for. This is the code I ended up with.


var params = arguments[0], $ = skuid.$, updates = params.updates; // if the process reference field is updated by the user, // then get the value of default sequence field for that row // check that field is being pulled into the Process Model in your page if ('RECON__Process__c' in updates) { var processModel = skuid.$M('CurrentLibProcess'), proModCond = processModel.getConditionByName('ProId'), defaultSequence; // set and activate condition processModel.setCondition(proModCond,params.row.RECON__Process__c); processModel.activateCondition(proModCond); // query model and wait til done before getting row and updating row $.when(processModel.updateData()) .done(function(){ processRow = processModel.getFirstRow(); defaultSequence = processRow.RECON__Sequence__c; params.model.updateRow(params.row,'RECON__Sequence__c',defaultSequence); }) .fail(function(){ }); }<br>



Nice. looks like you took it to another level there setting the conditions and querying the junction object.

Yup. As far as I know I had to do that. Still new to Skuid (3 months) and Javascript (1 month)

Well doneā€¦ quickly passing all of upā€¦Ā