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!
Joe,
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.
skuid.formula.Formula (<br> 'MODULUS',<br> function (number, divisor) {<br> return number % divisor;<br> },{<br> namespace: 'customMath',<br> numArgs : 2,<br> returnType : 'number'<br> }<br>);
When you want to reference this in a formula field, you would use it as follows:
customMath__MODULUS({{Number1}}, {{Number2}})
Thanks,
Bill
Hi Joe and Bill,
You can use the mod function in a Skuid formula like this:
{{input}}%10
The 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
Luzie,
Thanks for pointing that out!
Will other operators like ‘++’ work?
Best!
Bill
Thanks guys, both of those solutions work for the mod part of it, but now I’m having some trouble with the date function. I always have trouble manipulating dates in Skuid.
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.
Not as far as I know. Could you let me know more details why you would need that? Would the following also meet your needs?
{{input}}+1
Good to hear that the mod part works now regarding calculations with date&time, I once posted a detailed guideline here:
https://community.skuid.com/t/difference-between-2-datetime-fields
Is that helpful for you?
Luzie,
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
Joe,
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
Great! We are always interested in the ideas that come up in the community let me know if run into a specific scenario where the {{input}}+1 does not solve the issue.
Thanks Bill!
Joe, please let me know if there are any questions left
Thank you for your patience! Skuid has fixed the issue regarding Modulo operator not being listed as an operator in UI-Only formula fields (issue CORE-1934) in the new 12.1.9 release which is now available on the Skuid Releases page.
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 functionality before 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!Â
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.