I am looking for a method to automatically hide a user submitted custom module item from public display once the user has been removed from a specific secure zone.
Hi @Erik
The Custom Module item will have a property of CreatedByMemberId
which you can use to then do a look-up of that CRM record and loop through their Secure Zones (or lack thereof).
Using: {% component type: "CRMContacts" %}
Make sure to include the Secure Zone data by setting the parameter includeSecureZonesInfo: "true"
Youâll also need to have the âAllow listing my contact data in the CMSâ option enabled in the userâs CRM record, or have the global setting enabled for âAllow listing CRM contacts dataâ in: Miscellaneous Settings
So your CRM lookup might look like this inside your Custom Module item layout:
{% component type: "CRMContacts", layout: "", filterBy: "Id", filterValue: "{{this.CreatedByMemberId}}", limit: "1" collectionVariable: "userZones" %}
Then to do the check:
{% assign hasZone = false %}
{% if userZones.items[0].id == this.CreatedByMemberId %}
{% for zone in userZones.items[0].SecureZones %}
{% if zone.id == "1234" %}
{% assign hasZone = true %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}
Replace 1234
with the ID of your Secure Zone.
(the first IF statement here checks if the returned CRM record matches the one you are look for, because the CRMContacts component will return all records if the filter you specify doesnât exist - so youâd end up with the wrong CRM record)
Then you can use the variable {{hasZone}}
to show or hide the item:
{% if hasZone == true %}
<!-- show your layout/item -->
{% endif %}
Adam, Legend! Thank you much appreciated. Iâll give it a go. Also is there a way to automatically notify a CRM contact via system email once their secure zone access has exprired?
There is no current notification system for expired secure zones.
You could perhaps create a custom report for âContacts and Secure Zonesâ and sort by zone expiry date to identify recently expired contacts?
Although this would be a manual process to check the report periodically.
Thank you! Much appreciated.
Actually, if these items are being viewed online fairly frequently/med-high traffic, then you could perhaps render a hidden form when an item is blocked, which is then auto-submitted via AJAX, eg:
{% if hasZone == true %}
<!-- show your layout/item -->
{% else %}
<!-- NOTIFICATION FORM -->
{% endif %}
The form could be populated via Liquid with the CRM ownerâs email so that they get the autoresponder.
Youâd also want to put a check in place to only render this form if there isnât a case file already for that CRM contact for this form (to stop it being submitted multiple times).
Hope this makes sense.
Basically, weâre utilising other visitors to the site to trigger the notification based on if an item is blocked due to an expired secure zone status.
Itâs a bit of a hack
Adam,
Member signup form has field âallow lising my contact date in the cmsâ ticked.
Render list of items on page: {% component source: "Art News", layout: "List", sortBy: "releasedate", sortOrder: "DESC", limit: "100", collectionVariable: "itemList", type: "module", includeSecureZonesInfo: "true" %}
Custom module list layout: `{% component type: âCRMContactsâ, layout: ââ, filterBy: âIdâ, filterValue: â{{this.CreatedByMemberId}}â, limit: â1â, collectionVariable: âuserZonesâ %}
{% assign hasZone = false %}
{% if userZones.items[0].id == this.CreatedByMemberId %}
{% for zone in userZones.items[0].SecureZones %}
{% if zone.id == â1057â %}
{% assign hasZone = true %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}
{% if hasZone == true %}
...... {% endif %}`I have submitted an item as a member but it does not show in the list. what am i missing? thank you in advance.
Hi @Erik
In your List layout, after the CRMContact component, do you get any output when just trying to render:
<pre>{{userZones}}</pre>
Are you the member who submitted the item?
interestingly although the user can login and is associated to the zone it does not seem to show.
SecureZone is empty.
Oh right. You need to add the parameter includeSecureZonesInfo: "true"
to the CRMContact component.
You are a legend. Thank you so much. It works now!
is there an easy way to also hide the custom modile item if secure zone id equals id âXâ and access to the specific zone has expired?
Perhaps not an easy way, but itâs certainly possible.
You already have the first part @Erik with the checking for Zone ID, we just need to add in the expiry date check too:
{% assign hasZone = false %}
{% assign isZoneXandExpired = false %}
{% for zone in userZones.items[0].SecureZones %}
{% if zone.id == â1057â %}
{% assign hasZone = true %}
{% elsif zone.id == âXâ %}
{% assign nowSec = "now" | date: "%s" | plus: 0 %}
{% assign expirySec = zone.expirydatetime | date: "%s" | plus: 0 %}
{% if nowSec > expirySec %}
{% assign isZoneXandExpired = true %}
{% endif %}
{% endif %}
{% endfor %}
{% if hasZone == true %}
<!-- items if zone 1057 -->
{% endif %}
{% if isZoneXandExpired == false %}
<!-- items if zone X and not expired -->
{% endif %}
{% if hasZone == true and isZoneXandExpired == false %}
<!-- COMBINED CONDITION: items if zone 1057 and zone X and not expired -->
{% endif %}
I havenât tested this code but it should be pretty close (if Iâve understood your requirements).
That worked a treat. thank you so much Adam!
@Adam.Wilson Interestingly the code works if a member was added to the zone manually. If the member is added to the secore zone via a payment form it does not work. I canât see why?
@Erik are you referring to the isZoneXandExpired
check?
Try rendering out the full Liquid object and compare the output between the 2 different types of members:
<pre>{{userZones}}</pre>
See if there is anything different or missing with their secure zone info.
Maybe the zone expiry date is not being set correctly when registering via the form?
Member who has used payment form.
So there is no contact data being returned.
Do they have "allow lising my contact date in the cmsâ ticked?
Also, does the filtered ID 34158
match the memberâs ID who is logged in?
Thank you "allow lising my contact date in the cmsâ ticked? was not ticked on the payment form.
I was not aware that was needed as the user had already used onother secure zone sign up form prior to payment where the "allow lising my contact date in the cmsâ was ticked.
It shouldnât be needed again, but perhaps with it not being ticked on the second submission then actually turned if off.