unable to clear field values after unrendering

  • 1
  • Problem
  • Updated 2 years ago
Hi,

I have a picklist field Test_a which is rendered with Test_b and Test_c
when Test_a is set to Yes then it will display the fields Test_b and Test_c,
but when I select Test_a as No I can still see the data for Test_b and Test_c in the database, when I set Test_a back to Yes the data is still there under Test_b and Test_c

Is there any way where I can clear the data when the fields are not rendered.

Please let me know if there is any JS or easy workaround.

Thanks in advance!




 
Photo of Linga

Linga

  • 228 Points 100 badge 2x thumb

Posted 2 years ago

  • 1
Photo of Conlan O'Rourke

Conlan O'Rourke

  • 3,280 Points 3k badge 2x thumb

Did you set the Render property to "If hidden, Model field changes should be...Cancelled"

The default setting is "Retained in Model"...which means even after un-rendering, the data stored in those fields would be Retained in the Model, and thus saved to the server on the save action.


Photo of Linga

Linga

  • 228 Points 100 badge 2x thumb
Yes Conlan, I did set the value to 'Cancelled'
but I can still see the data
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
If the data for the hidden fields is already saved in salesforce, you'll have to run actions to update the values of those fields to {{blank}}.

Here's one solution:

Use a model action that runs when Test_a changes. The action framework sequence should:
  1. Use a branch to check if Test_a is 'No'. if it is, then
  2. update field on row: Test_b = {{blank}}
  3. update field on row: Text_c = {{blank}}
Photo of Linga

Linga

  • 228 Points 100 badge 2x thumb
Hi Matt,

Could you be more specific regarding the below point
  1. Use a branch to check if Test_a is 'No'. if it is, 
Thanks much
Photo of Linga

Linga

  • 228 Points 100 badge 2x thumb
Sorry it worked.. but it is not saving the data back to database, am I doing something wrong?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
If you want it to save automatically, just add a save action to the end of the sequence.
Photo of Linga

Linga

  • 228 Points 100 badge 2x thumb
Hi Matt,

it was not saving the data, even after including the save action.

I had included JS for the save button and its working perfectly

var params = arguments[0],    $ = skuid.$;

var myModel = skuid.$M('Test');
var rowsToUpdate = {};
var rows = myModel.getRows();

$.each(rows, function(i, row) {
    if (row.Test_a__c == 'No') {
        rowsToUpdate[this.Id] = {
            Test_b__c: false,
            Test_b__c: false
        };
    }
});

myModel.updateRows(rowsToUpdate);