web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Customer Service Porta...
Power Pages
Unanswered

Customer Service Portal - Liquid expression to populate field values based on the current contact.

(0) ShareShare
ReportReport
Posted on by 1,710

Hello,

In my environment I have the "Customer Self Service Portal", inside this portal there is a "Web Create Case" form. In this form, there is a field for Customer(Account), Contact and another field that I have created called "Services" as an option set. Also, the same Services field exists in the Contact entity. (Each contact can have one service)
Capture.JPGCapture1.JPG
For example:

 

contactid:1
contactname:test
new_services: Office 365

 


What I am trying to achieve is the following:
I want to populate after page load the service value based on the current filled Contact value from the Contact entity.

I have found something similar to my requirement but it's based on "Account" value not the "Contact". Please have a look below:

 

<p>{% assign account = entities.account[{{user.parentcustomerid.id}}] %}</p>

<p><span hidden="" id="optionSetValues">{{account.new_countries.value}}</span>
</p>

window.onload = function(){
 
document.getElementById("new_country").value = document.getElementById("optionSetValues").innerHTML;
document.getElementById("optionSetValues").style.display = "none";

}

 

Can someone please provide an example using liquid expression to get the current contactid inside the form?

Any help will be greatly appreciated.
Thank you.

Categories:
I have the same question (0)
  • Satish1024 Profile Picture
    279 on at

    Hey Julien,

     

    You dont need the first statement, as you don't need the account anymore. 

    Hence removed: <p>{% assign account = entities.account[{{user.parentcustomerid.id}}] %}</p>

     

     

    Contact is accessible from user object. hence, I modified the code like this.

    <p><span hidden="" id="optionSetValues2">{{user.new_services.value}}</span>
    </p>
    
    <script>
    window.onload = function(){
    document.getElementById("logical name of the services field on Case form").value = document.getElementById("optionSetValues2").innerHTML;
    document.getElementById("optionSetValues2").style.display = "none";
    }
    </script>

    Replace the logical name of the services option set above.  

  • v-xida-msft Profile Picture
    on at

    Hi @Julien2 ,

    Do you want to populate the Services field based on the Contact field value within your Entity form?

    Further, do you want to get the current contactid typed inside the form?

     

    Based on the needs that you mentioned, I think Liquid page tag could achieve your needs. Please consider take a try with the following workaround:

    {% assign contactId = page['logicname of Contact field in the form'].Id %}

     

    Then you could use the following formula to get the corresponding Option Set field value and set it into the Services field:

    <p>{% assign contact = entities.contact[page.'logic name of Contact field in the form'.Id] %}</p>
    <p><span hidden="" id="optionSetValues">{{contact.'loigc name of Services field'.value}}</span>
    </p>
    
    <script type="text/javascript">
    window.onload = function(){
     document.getElementById("optionSetValues").style.display = "none";
    };
    document.getElementById("logical name of the services field on Case form").addEventListener("change", function(event){
     document.getElementById("logical name of the services field on Case form").value = 
     document.getElementById("optionSetValues").innerHTML;
    })
    </script>

     

    Please consider take a try with above solution, check if the issue is solved.

     

    Best regards,

  • EBMRay Profile Picture
    1,710 on at

    Hello @Satish-Reddy  @v-xida-msft ,

    Thank you for providing examples.

    I have figured out that, the "Services" field type in the form (Case entity) is a Lookup and not an option set. Since in the contact entity the "Services" field is an Option Set.

    The Lookup options values have different numbers than the option set values.
    For example, all the option set values start with 1000000 since the lookup values contain a GUID.
    Option Set:

    <option selected="selected" value="" label=" "> </option>
    <option value="100000000">Azure</option>

    Lookup:

    <option value="" label=" "> </option>
    <option value="926b6362-c079-e911-a988-000d3aba0bee">Azure</option>


    In our logic, we are saying that the services field value inside the contact entity should be equal to the services lookup value. As a result, they will never be equal so the value will be never assigned inside the services field which is the problem that I am facing right now.

    I have thought of a workaround that is creating a new "Services" field as an option set type inside the form and removing the other field, but it's not a good idea.

    I would like to ask you how can I assign the option set value inside the lookup field value?

    I was able to get the value of the right service assigned for the user signed-in using {{user.new_services.value}}.

    Looking forward to your response.
    Regards,
    Julien

  • Verified answer
    v-xida-msft Profile Picture
    on at

    Hi @Julien2 ,

    Do you mean that the "Services" field is a LookUp field in your Case Entity Form, which reference values from the Contact Entity?

    Do you want to assign the option set value inside the lookup field value within the Case Entity Form?

     

    If the "Services" field is a LookUp field in your Case Entity Form, which reference values from the Contact Entity, please modify above formula as below:

    <p>{% assign contact = entities.contact[page.'logic name of Contact field in the form'.Id] %}</p>
    <p><span hidden="" id="optionSetValues">{{contact.contactid}}</span>
    </p>
    
    <script type="text/javascript">
    window.onload = function(){
     document.getElementById("optionSetValues").style.display = "none";
    };
    document.getElementById("logical name of the services field on Case form").addEventListener("change", function(event){
     document.getElementById("logical name of the services field on Case form").value = 
     document.getElementById("optionSetValues").innerHTML;
    })
    </script>

    using the following Liquid template expression to get the Unique Identifier value (GUID value) of the selected Contact value within the Contact LookUp box:

    {{contact.contactid}}

    you could use the following expression to get the contact id of current sign in user:

    user.contactid

     

    Best regards,

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard