Access previous value of field?

Matt SonesMatt Sones 💎💎💎
edited June 25, 2020 in Questions
If I have a model with unsaved changes, is there a way that I can access the value of a changes field that is still on the server (the saved version)?

An example:

I have field Date__c which is a DateTime.
I change Date__c in the skuid model.
Before I save the model, can I access the value of Date__c on the server, (and compare it to Date__c in the model?)

Comments

  • Pat VachonPat Vachon 💎💎💎
    edited June 25, 2020
    The model has these values.
    image
  • Matt SonesMatt Sones 💎💎💎
    edited February 10, 2017
    Sweet. Thanks, Pat. I thought it had to be there somewhere... I just missed 'originals' when I did a quick scan.
  • edited July 18, 2018
    Is there a simple way to display the original value in a template without a js snippet?
  • Barry SchnellBarry Schnell 💎💎
    edited November 18, 2016
    Hi Jared -

    Unfortunately, I don't think there is a way without some javascript.

    In theory, you could write a simple UI only field such as:

    {{$Model.Account.originals.{{Id}}.Name}}

    However, merge syntax inside of merge syntax isn't supported currently and since there is no way to "concatenate" inside of a formula and then process merge syntax to the concatenated result your left with JS.

    You have a couple of options:

    1) Create a UI only field for each original you care about.  Then, write a JS snippet that is triggered on model events like row.updated.  In the JS, update the UI only field (make sure to use updateRow api) to correspond to originals values and then use the UI only field anywhere on your page.

    2) Write a field renderer that displays the original value that you want displayed.  On your component (e.g. field editor, table, etc.) add a field for the field that you are concerned with (e.g. Name) and then set to use the custom renderer.  It's important to use the actual field that you care about in all cases because you want that field to re-render when it changes elsewhere in order to display the original.

    Hope this helps!
  • edited April 13, 2016
    Many thanks, Barry...again.  I forgot that I hadn't thanked you and a couple weeks slipped by.

    I ended up using the first option, but it took me way longer than it should have to figure out the correct syntax to access the original value (as I am relearning javascript after many years of neglect).
    The error handling is due to the fact that original value is undefined until an update occurs.

    On the chance that this may help others, here's a snippet for a custom renderer that captures the original value of the field.

    var $ = skuid.$,    params = arguments[0],
        values = arguments[1],
        model = arguments[0].model,
        row = arguments[0].row,
        element = arguments[0].element;
        
        var originalValue;
        var rowId = row.Id;
    try {
        originalValue = model.originals[rowId].Latest_Update__c;    
    } catch (e) {
        originalValue = values;
    }
    element.append( originalValue );

    Many happy returns!
  • Barry SchnellBarry Schnell 💎💎
    edited November 18, 2016
    No worries Jared, your welcome - glad you got it working!
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!