Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

{Portal} Dynamically set a field label using Liquid

Posted on by Microsoft Employee

I have a unique requirement where I need to dynamically update a Field's label on a portal page.  I know how to grab the dynamic value that I need to append the field label with, but I am not sure how to update a field's label, or if it is possible.  Just looking for some liquid code to adjust the field label on the form.  Example of what I am looking for:

CRM Form field label: Previous Year's Sales

Desired Portal field label: 2018 Year's Sales

I have the ability to get the "2018" text, I just need to inject it into that field's label.

Thanks in advance!

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: {Portal} Dynamically set a field label using Liquid

    Thanks, Aric.

    Because I did not want to display the Year field anywhere on the portal page, I decided to use Liquid code to get the "2018" value.  I then set these values as Javascript variables in a function, and used your code to adjust the field name. It looks something like this (in a Web Template):

    {% assign account= entities.account[request.params.id] %}

    {% if account%}

     {% assign currentyear = account.yearfield.label %}

           {% endif %}

    <script>

    $(document).ready(function () {

     $('#field').text("{{currentyear}} Year Sales");

    });

    </script>

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: {Portal} Dynamically set a field label using Liquid

    You can use jquery for this. Get the name of the field, and modify the properties as follows:

    var fieldName = "new_yearsales";

    var fieldLabel = "2018 Year's Sales";

    $('#new_yearsales_label').text(fieldLabel);

    Notice that the jQuery field names prepends the # sign, and suffix the _label in order to change the label.

    This code will have to go in your Custom Javascript section of the Entity form:

    $(document).ready(function () {

      $('#new_yearsales_label').text("2018 Year's Sales");

    }

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans