Update a field value when another field is edited

Pat VachonPat Vachon ๐Ÿ’Ž๐Ÿ’Ž๐Ÿ’Ž
edited June 25, 2020 in Questions

Comments

  • Pat VachonPat Vachon ๐Ÿ’Ž๐Ÿ’Ž๐Ÿ’Ž
    edited June 25, 2020
    ^bump^ :D
  • edited January 31, 2015
    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.
    image
    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... :D

    Seth
  • Rob HatchRob Hatch ๐Ÿ’Ž๐Ÿ’Ž๐Ÿ’Ž
    edited June 25, 2020
    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.ย 

  • Pat VachonPat Vachon ๐Ÿ’Ž๐Ÿ’Ž๐Ÿ’Ž
    edited January 5, 2016
    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.
  • Pat VachonPat Vachon ๐Ÿ’Ž๐Ÿ’Ž๐Ÿ’Ž
    edited January 5, 2016
    It's the listening part that I'm new to. Once I have the Id, then I'm good to go.
  • edited December 4, 2017
    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], 
    $ = skuid.$,
    updates = params.updates,
    defaultSequence;
    //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 ('Process__c' in updates) {
    ย  ย ย defaultSequence = params.row.defaultSequence__c;
    ย  ย  }
    ย  ย  if (defaultSequence) {
    ย  ย  ย  ย  params.model.updateRow(params.row,'defaultSequence__c',defaultSequence); ย 
    ย ย ย }
    See if you have any joy with that!

    ย 
  • edited May 2, 2016
    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;

  • Pat VachonPat Vachon ๐Ÿ’Ž๐Ÿ’Ž๐Ÿ’Ž
    edited June 25, 2020
    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(){                                        });                      }
  • edited June 25, 2020
    Nice. looks like you took it to another level there setting the conditions and querying the junction object.
  • Pat VachonPat Vachon ๐Ÿ’Ž๐Ÿ’Ž๐Ÿ’Ž
    edited January 5, 2016
    Yup. As far as I know I had to do that. Still new to Skuid (3 months) and Javascript (1 month)
  • Rob HatchRob Hatch ๐Ÿ’Ž๐Ÿ’Ž๐Ÿ’Ž
    edited September 1, 2016
    Well done... quickly passing all of up...ย 
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!