# Replicate Salesforce Mod Function

Hello

I have a need to calculate the date of the previous Friday. Since the mod function is not available for Skuid formula fields, I am currently doing this with a Salesforce formula field:

(TODAY()) - MOD(TODAY() - DATE(1900,1,12),7)

This will return the date of the previous Friday, so if calculated on 5/10/2018 it will return 5/4/2018. Since Salesforce formula fields are not calculated until the record is saved, when displayed on a new record page in skuid this field will be blank until the row on the model is saved. I am trying for a way to display this on a new record page while the new record is still being edited and before it is saved.

The mod function basically takes a number, divides it by another number, and returns the remainder. Is there any way to replicate this in a Skuid UI-only formula?

Thanks!

I have a need to calculate the date of the previous Friday. Since the mod function is not available for Skuid formula fields, I am currently doing this with a Salesforce formula field:

(TODAY()) - MOD(TODAY() - DATE(1900,1,12),7)

This will return the date of the previous Friday, so if calculated on 5/10/2018 it will return 5/4/2018. Since Salesforce formula fields are not calculated until the record is saved, when displayed on a new record page in skuid this field will be blank until the row on the model is saved. I am trying for a way to display this on a new record page while the new record is still being edited and before it is saved.

The mod function basically takes a number, divides it by another number, and returns the remainder. Is there any way to replicate this in a Skuid UI-only formula?

Thanks!

Tagged:

1

#### Categories

- 7.9K Questions
- 926 Ideas
- 220 Discussion Categories
- 178 General
- 9 Community Feedback
- 3 Community Info
- 18 Knowledge Base

## Comments

You can create your own custom formulas using Skuid. See this page-> https://docs.skuid.com/latest/en/skuid/api/skuid_formula.html

Here is a sample that worked for me in Skuid 11. I think custom formula fields were enabled as of Skuid 10. Just put this into an inline snippet. If you want to use this on other pages, then create a static resource and reference that static resource on any page where you need it. When you want to reference this in a formula field, you would use it as follows: Thanks,

Bill

You can use the mod function in a Skuid formula like this:

{{input}}

%10The sample above returns the remainder after the input value has been divided by 10.

I'm afraid that this is not covered in the documentation. I will double check it and let the documentation team know that it needs to be added, if necessary.

Greetings,

Luzie

Thanks for pointing that out!

Will other operators like '++' work?

Best!

Bill

What the function is doing is subtracting today's date from a Friday way in the past. Then divides that value by 7 and takes the remainder. Then subtracts that remainder from today's date to return the previous Friday. If it is currently Friday it should return Today's date.

I'm wondering if this would be easier to use a Skuid UI formula or a custom Javascript formula like Bill's solution to do the whole thing.

{{input}}+1

https://community.skuid.com/skuid/topics/difference-between-2-datetime-fields

Is that helpful for you?

Thanks for the reply. I should have put on my question...'I was wondering if...' The '[[input}} + 1' works...just wanted to understand the breadth of operators that would work. I can test this out myself.

Thanks!

Bill

Luzie write up is very good...hopefully that helps you. I would say that you want to keep it as a Skuid UI formula field. This will let Skuid handle any conversions needed for timezone and between Salesforce date/time to Javascript date/time.

Thanks,

Bill

Joe, please let me know if there are any questions left :-)

As a reminder, Salesforce does NOT allow reverting back to prior versions of managed packages. Skuid always recommends installing new versions in a non-business critical sandbox environment to test

all mission critical functionalitybefore installing into a production environment. We also recommend that you update out of date themes when you upgrade. Please let us know if you continue to encounter any problems with this issue after upgrading.Thanks again for alerting us of these issues!