cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
QuantumRemedy
New Member

Need access to a field in Contact entity for use in form for another entity

I have a custom entity called Projects and it has an administrative section on the form. My plan was to use a field I created on the Contacts object called "Group" to use JavaScript to hide/show the administrative section on my Projects form. The form is opened from an entity list and can be read-only or edited and I have the buttons setup on the entity list for this.

 

My first attempt was to create a hidden input with the "Group" value on the current contact populated using liquid. Then I planned on using custom JavaScript on the form to check that hidden input and hide/show the administrative section properly on the edit form. This doesn't work because the form's JavaScript seems to be encapsulated so that it can only work inside the form and not on the page as a whole. Attempts to retrieve the hidden input by ID result in a null reference with vanilla JavaScript and a length of 0 with JQuery.

 

It would be nice if I could inject liquid into the form, but I can find no way to do that. Is there any other way of sharing this data to the form?

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @QuantumRemedy ,

If you only have access to javascript of the form you can use liquid directly there and omit of using hidden fields whatsoever. It will look like this:

$(function() {
  // crete variable directly instead of input
  var userGroup = "{{user.new_contactgroup | default: 'unknown'}}";
  // .. show/hide logic ...
});

 

----------------------------------------------------
If you find this post helpful consider marking it as a solution to help others find it.

View solution in original post

4 REPLIES 4
justinburch
Microsoft
Microsoft

Hi @QuantumRemedy,

The path you attempted is correct, just move your hidden input to the Web Template. E.g.

Page Template: Full Page

Web Template = Projects Template

Web Template: Projects Template (this is your choice - add to existing template, copy & alter, or add the input and use "include" tag to make the existing template below it)

 

{% extends 'Layout 1 Column' %}

{% block main %}

  <input type="hidden" id="contact_group" val="{{ user.new_contactgroup | default: 'unknown' }}">

  {% if page.entityform %}

    {% entityform id:page.entityform.id %}

  {% endif %}

{% endblock %}

 

 

EntityForm "Custom JavaScript"

 

$(function() {
  var userGroup = $("#contact_group").val();
  // .. show/hide logic ...
});

 

 

EDIT: I just realized you might be saying the EntityForm is a modal - if that's the case, you'll need to use window.parent (possibly multiple levels of .parent) to access the content in the page with the list & hidden input. Try adding a debugger line in the Entity Form JS and use the dev console to find the right path

Hi @QuantumRemedy ,

If you only have access to javascript of the form you can use liquid directly there and omit of using hidden fields whatsoever. It will look like this:

$(function() {
  // crete variable directly instead of input
  var userGroup = "{{user.new_contactgroup | default: 'unknown'}}";
  // .. show/hide logic ...
});

 

----------------------------------------------------
If you find this post helpful consider marking it as a solution to help others find it.

View solution in original post

Yes, it is a modal form, I should have stated that is the issue! I think your solution might work but as I was trying it, @OOlashyn posted a solution that entails using liquid inline in the JavaScript and it worked right off. This seems to be a more elegant solution but thank you for your answer as I may need to try what you suggested for other purposes inside modal forms in the future.

 

Thanks!

Thanks @OOlashyn! This was exactly what I needed. I didn't know that liquid worked when put in the custom JavaScript, but I'm not sure why I didn't try it before. This is perfect!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Users online (74,511)