Validating a field on Save. Help Please!

  • 2
  • Question
  • Updated 2 years ago
  • Answered
Hi,

I'm working on a validation issue where the field that needs to be validated has to be compared to a field from another model on the save button. I am pretty sure this has to be done with a snippet code. I wanted to see if someone can point me in the right direction.

-Thanks,
Adam N
Photo of anwaozo

anwaozo

  • 436 Points 250 badge 2x thumb

Posted 2 years ago

  • 2
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Any reason you can't use a Salesforce validation rule?
Photo of anwaozo

anwaozo

  • 436 Points 250 badge 2x thumb
The page I'm working with is a Skuid Page that we used to replace the salesforce page. 

This issue is when a sales rep creates a "New Sales Order" the field that needs to be validated is the "Customer" field. That field need to reference another field in the billing object so if that customer has a past due balance my sales rep will get an error message stating such on the save action.

I hope this makes sense.  


 
Photo of anwaozo

anwaozo

  • 436 Points 250 badge 2x thumb
var model = skuid.model.getModel('Billing'),row = model.Days_Since_Billing_Date__c();

if (row.Days_Since_Billing_Date__c >= 75) {
  alert("I am an alert box!");
} else {
  save()
}



This is the code I started. 
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
I'd favour using a server side validation rule. Is the billing object child to Account as Master? If so, use a rollup on Account and create the validation rule on Sales Order.
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
You could use the Action Framework "Branch" Action Type, with an "If-True Action" that displays an error message, otherwise the Action sequence can continue to a "Save Models" Action.

The "Formula" for the Branch Action would be something like this:

{{{$Model.Billing.data.0.Days_Since_Billing_Date__c}}} >= 75

You could also / alternatively define an Enable Condition on the Save button that causes the button to be disabled if the Days Since Billing Date >= 75.
Photo of anwaozo

anwaozo

  • 436 Points 250 badge 2x thumb
I dont see the branch action type. 
Photo of anwaozo

anwaozo

  • 436 Points 250 badge 2x thumb
Nvm. I found it. Let me try it. 
Photo of anwaozo

anwaozo

  • 436 Points 250 badge 2x thumb
Zach, I was not able to find that  "Branch" Action Type, or the "If-True Action". Ca you help please?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Here you go.

To create True Branch


True Branch


False Branch