Conditional Popup/Warning after save

  • 1
  • Question
  • Updated 3 years ago
  • Answered
HI,

I'm trying to accomplish the following, and not sure it's possible with Skuid.

After saving a record I would like for a way to  show a popup/warning if certain conditions are met or not met

Example of my main use:

I have a formula field to validate certain numbers entered. If that formula result does not match a value entered in X field, I want to be able to show that warning/popup

The reason i cannot use SF validations, is that in certain cases, it will not match, but I still want to be able to show the Warning, so they can double check the #s entered.

The problem i'm experiencing is that the condition has to be after Save is executed, as formula field would only calculate after save.

This is the reason i cannot use a custom "save button" with multiple actions and conditional rendering.

Basically the order of actions would be
-Save
-Check 1 or more conditions
-If condition(s) met, to show the popup/warning

if anyone could help me out, i will appreciate it

If need more details do not hesitate to ask

Thank you
Photo of Dave

Dave

  • 5,538 Points 5k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Dave,

This will take a little javascript, but you can do it!

create a javascript snippet in your action framework that looks something like this:

// get your model and row
var model = skuid.$M('MyModel'),
row = model.getFirstRow();
//set your shortcuts and initial variables.
returnVal = true;
$ = skuid.$;
//get the values of the formula fields you're interested in:
var value1 = model.getFieldValue(row, 'MyFormulaField1__c'),
value2 = model.getFieldValue(row, 'MyFormulaField2__c');
//Create your conditional statements
if (value1 == 'Some value which should case the popup' || value2 == 'Some other value which should cause the popup') {
returnVal = false;
}
return returnVal;

Your action framework should include this snippet after save, and include the warning popup as an 'on-error' action.
Photo of Dave

Dave

  • 5,538 Points 5k badge 2x thumb
Matt,

I just tried the JS you provided and it was a breeze, thx to Script provided. And ty for comments added, it will allow me to modify this script for different uses :)

Now do you know by any chance, how can i get my custom Save button to behave same as the standard Skuid Save Button (greyed out until some field has been changed)?

I see an old post from yrs ago but could not find anything recent
https://community.skuidify.com/skuid/topics/how_do_i_en_dis_able_a_custom_save_button

Thx again
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
As an alternative to all of that, you could just build your formula fields as ui-only formula fields in skuid, and then you could do the validation immediately, before save.
Photo of Dave

Dave

  • 5,538 Points 5k badge 2x thumb
Matt,

I tried the UI Only approach quickly but did not seem to work for me but will try again .

But ty very much for javaScript, I'm sure that will be extremely useful if i cannot do it with UI fields (specially that i have no JS knowledge ) :)

Thx!
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Dave,

Try "enable conditions" under rendering when you click on your button in the builder. Se the condition to enable when the model has unsaved changes (model properties).
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Dave,

What exactly is the issue that you're experiencing?

.getFieldValue() is always the way to get the field value. Check out the skuid api documentation if you haven't yet.
Photo of Dave

Dave

  • 5,538 Points 5k badge 2x thumb
Matt,

I Actually did check it out and saw something for .getfield(field) and even tried that, but to no avail, so wondered if i missed something.

The issue I'm experiencing is that it saves the record and does not show popup even though conditions are met (value1 and value2 are not equal & value3 is null)

When i try with only Value1 != Value2 it works fine and i get popup as expected

For same record I no longer get the popup once i add the condition value3 is null.

Thx
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
have you tried (value1 !== value2 && !value3) ?
Photo of Dave

Dave

  • 5,538 Points 5k badge 2x thumb

Yes , just and same result, popup not triggering :(


For testing purposes, I just removed first condition and first 2 values and only tried the value3 condition and it worked....

So I left it as condition, and added the other ones after and it worked.

No idea why, but it works lol :)

// get your model and row
var model = skuid.$M('BankStatement'),
row = model.getFirstRow();
//set your shortcuts and initial variables.
returnVal = true;
$ = skuid.$;
//get the values of the formula fields you're interested in:
var value1 = model.getFieldValue(row, 'Warning_Acknowledged__c');
value2 = model.getFieldValue(row, 'Ending_Balance_Calculated__c');
value3 = model.getFieldValue(row, 'Ending_Balance__c');
//Create your conditional statements
if (value1 === null && value2 != value3)  {
returnVal = false;
}
return returnVal;

Thank you for all your help and if you do understand the reason reverse works, I'm curious to know :)


Photo of Dave

Dave

  • 5,538 Points 5k badge 2x thumb

I would like to correct my previous post.

The issue was not the order, I must have refreshed too fast...

I finally found it I have to bracket the second condition:      && (value2 != value3 ) )




// get your model and row
var model = skuid.$M('BankStatement'),
row = model.getFirstRow();
//set your shortcuts and initial variables.
returnVal = true;
$ = skuid.$;
//get the values of the formula fields you're interested in:
var value1 = model.getFieldValue(row, 'Warning_Acknowledged__c'),
value2 = model.getFieldValue(row, 'Ending_Balance_Calculated__c'),
value3 = model.getFieldValue(row, 'Ending_Balance__c');
//Create your conditional statements
if (value1 === null && (value2 != value3))  {
returnVal = false;
}
return returnVal;