Adding two UI-only formula fields from different models

Andrew NAndrew N Member
edited June 3 in Questions
Apologies if this is a junior question, but I searched here in the community and couldn't find a good answer to my problem.

Right now I have two different aggregate models. Each aggregate model has a UI-only formula field that results in a number. I would like to take these two numbers and add them together and present that number to the user on their dashboard.

Is there a way to do this in SKUID? Let me know if you need additional information.

Thanks in advance,
Andrew

Comments

  • Zach McElrathZach McElrath Skuad
    edited May 18
    You can create a "Ui-Only" Model whose only purpose is to have its own Ui-Only Field that takes the two values from the two Aggregate Models and adds them together. Create the Model on a Salesforce object that everyone would have the ability to create, e.g. Task, Contact, whatever, it doesn't matter. Then have this Model set to NOT Load Model Data on Page Load, and to "Create Default Row if Model Has None". Then add a Ui-Only Formula Field to this model, whose Formula basically just takes the values from the two Aggregate Models and adds them together, e.g.

    {{$Model.AggModel1.data.0.SomeField}} + {{$Model.AggModel2.data.0.SomeField}}


  • Andrew NAndrew N Member
    edited December 2016
    Zach - I really appreciate the detailed reply. That worked perfectly.

    Thanks again,
    Andrew
  • edited June 3
    Hi Zach,

    Is it possible to use fields from a different model with a UI field that's on one of my Aggregate Models? I'm trying to get a percent of total field. I have an Aggregate Model that is grouped by Opportunity owner (Model1), and another Aggregate Model (Model2) with no groupings that is the total Amount.

    I'd like to create a UI field on the grouped Agg Model that is: {{sumAmount}} / {{$Model.Model1.data.0.sumAmount}}

    When I try to do this I get an error message in the developer console, "TypeError: Cannot read property 'displaytype' of undefined".

    Am I missing something? Or better yet, an easier way to do this without creating a second model?

    Thanks,
    Chelsea
  • edited May 2016
    Chelsea,

    Your approach is good.  You just need to make sure that your aggregate 'name' is different between models.  Notice that in your formula for the model ui field you are trying to reference {{sumAmount}} for the numerator and denominator.  Even though these 'aggregates' are in 2 different models, I think Skuid just looks at both as 'sumAmount'.  Since they have the same name, you get an error.

    Try renaming your Model1 aggregate from 'sumAmount' to 'totalAmount'.  To do this, click on the aggregate field in the model and look for 'Alias Name' in the upper right.
    image
    Best,

    Bill
  • edited February 2016
    Hi Bill,

    Thanks for the quick response! Unfortunately, it's giving me the same error message. Also, I had a typo in my previous message. I meant to write: {{sumAmount}} / {{$Model.Model2.data.0.sumAmount}}

    I changed the name in my Model2 Agg to totalAmount with no luck. I even tried creating a UI only field on Model1 with just this: {{$Model.Model2.data.0.totalAmount}}

    This still gave me the same error. Any other ideas?

    Thanks so much for your help.
    Chelsea
  • Josh MerrittJosh Merritt Member
    edited February 2016
    Chelsea,

    Model order can be important in Skuid, so you might try putting model2 above model1 or vice versa. 

    Can you verify that Model2 has data in it? The easiest way I've found is to put a table on your page, tied to Model2, then add the fields you're trying to access. If you can get the total to display in the table, it should be able to be pulled into another model using your merge syntax: {{$Model.Model2.data.0.totalAmount}}

    You may need to group your model2 to get data point you're wanting.

    Another option is to use the MODEL_LOOKUP function available within the UI-only formula field.

    If you're still having trouble, sharing screenshots in a new post will give you more eyeballs on the issue. 

    HTH,
    josh
  • edited February 2016
    Hi Josh,

    Moving the Model2 above Model1 worked perfectly! Thank you for your help on this.
  • Josh MerrittJosh Merritt Member
    edited February 2016
    Glad to hear it was a simple solution!
  • Kaede HollandKaede Holland Member ✭✭
    edited September 2018
    Zach - Thank you so much for posting this solution! Works great! 

    When I load the page the field seems to be rendering as if were edited/modified (in italics, and colored with the lovely #bba005 color.) 

    The UI only field is set to be read-only. It's in a rich text component. Any suggestions? 
Sign In or Register to comment.