Skip to main content

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?)

The model has these values.


Sweet. Thanks, Pat. I thought it had to be there somewhere… I just missed ‘originals’ when I did a quick scan.


Is there a simple way to display the original value in a template without a js snippet?


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!


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 = argumentsa0],
    values = arguments=1],
    model = argumentsl0].model,
    row = argumentsr0].row,
    element = argumentse0].element;
    
    var originalValue;
    var rowId = row.Id;
try {
    originalValue = model.originalsnrowId].Latest_Update__c;    
} catch (e) {
    originalValue = values;
}
element.append( originalValue );

Many happy returns!


No worries Jared, your welcome - glad you got it working!