Ask: I (John) have a school(Account: Cornell University) for which John is a contact. This is OOB relation between Contact(John) and Account(Cornell University).
Upon login into the powerapps portal, the account to which John belongs should be auto-populated.
Solution: Below query will get the account details with which the user belongs. Then it can be used to set the value to the account lookup.
Code Below
<script type="text/javascript">
$(document).ready(function(){
//----------------------------------------------------------------------------
//Update account lookup in course level
{% fetchxml queryAccount %}
<fetch version="1.0" output-format="xml-platform" mapping="logical"
distinct="true">
<entity name="account">
<attribute name="name" />
<attribute name="accountid" />
<link-entity name="contact" from="parentcustomerid" to="accountid"
link-type="inner" alias="ae">
<filter type="and">
<condition attribute="contactid" operator="eq" value="{{user.id}}" />
</filter>
</link-entity>
</entity>
</fetch>
{% endfetchxml %}
//Get accountname and accountid
var recordCount = "{{ queryAccount.results.entities.size }}";//Assign liquid code varibale to javascript variable
if(recordCount > 0)
{
{% for resultAccount in queryAccount.results.entities %}
var accountName ="{{ resultAccount.name | escape }}";
var accountId ="{{ resultAccount.accountid | escape }}";
{% endfor %}
$("#new_institution_name").attr("value",accountName);//Display Name
$("#new_institution").attr("value",accountId);//Contact Id
$("#new_institution_entityname").attr("value","account");//Name of entity lookup
}
}
</script>
Comments
Post a Comment