Saturday 21 January 2017

Client Side Validation using Javascript in ADXStudio

As we all know that Adxstudio does not support CRM form Java Scripts and Business Rules, so you need to create your own client validations scripts on ADX forms whatever you have written on CRM forms.

ADX forms only make field mandatory if it;s mandatory in CRM, if you want to make field mandatory conditionally For Example: If 'State' field value is 'Other' then 'Other' field should be visible and mandatory.

For these type of validations you will have to write your own JavaScript :

The following example demonstrates adding a custom validator. This particular example forces the user to specify an Phone only if the another field for preferred method of contact is set to 'Phone'.

if (window.jQuery) {
   (function ($) {
      $(document).ready(function () {
         if (typeof (Page_Validators) == 'undefined') return;
         // Create new validator
         var newValidator = document.createElement('span');
         newValidator.style.display = "none";
         newValidator.id = "mobilephoneValidator";
         newValidator.controltovalidate = "mobilephone";
         newValidator.errormessage = "<a href='#mobilephone_label'>Mobile Phone is a required field.</a>";
         newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
         newValidator.initialvalue = "";
         newValidator.evaluationfunction = function () {
            var contactMethod = $("#preferredcontactmethodcode").val();
            if (contactMethod != 2) return true; // check if contact method is not 'Phone'.
            // only require Phone if preferred contact method is Phone.
            var value = $("#mobilephone").val();
            if (value == null || value == "") {
            return false;
            } else {
               return true;
            }
         };
 
         // Add the new validator to the page validators array:
         Page_Validators.push(newValidator);
 
         // Wire-up the click event handler of the validation summary link
         $("a[href='#mobilephone_label']").on("click", function () { scrollToAndFocus('mobilephone_label','mobilephone'); });
      });
   }(window.jQuery));
}


Note: Adxstudio forms only shows '*' on field label if the field is mandatory either in CRM or you are making the field mandatory using Entity Form Metadata.

If you making field mandatory using above mentioned ADXStudio given JavaScript code
It works well and make field mandatory, but it doesn't show '*' after field label.

Form will show field is mandatory on Submission of form at Top of the page.

If you want to show asterisk '*' on field label to let user know at the time of form filling, You need to write your own 3-4 line of JS code to show '*' after field label.

Here is the code to append asterisk on ADX form field:


 $('#inputfield_label_id').after('<span id="spanId" style="color: red;"> *</span>');                


Hope this post help someone, Please don't forget to write your feedback this will make me help to improvise and can provide you more and better content

Get Logged In User details using Liquid Template in ADXStudio

As we know that Liquid Template is one of the most powerful weapon of ADXStudio.

Today in this post i would like to share the information about how to get Current Logged In User details of ADXStudio Portal.

Where It is Useful ?


You might have came across so many requirements in which you require logged in user details -
  • Perform any Operation based on Current Logged In User.
  • Hide and Show Portal Content based on Current Logged In User.
  • Perform Redirection based on Current Logged In User. For Example: If  'User A' logged In on Portal, then he should be redirected to 'Page A' and 'User B' should redirected to 'Page B'.
  • Show different Home or Landing Page after Sign In based on Current Logged In User.
  • If User A has role Role A then do this, if Role B then do that.
  • Show Logged In User Account Details.
To achieve all the above requirements you must know about the Current Logged In User after sign in on Portal.

Liquid Template is the best way to achieve the same, Here is the example of the same:

'User'

{% if user %}
  Hello, {{ user.fullname }}!
{% else %}
  Hello, anonymous user!
{% endif %}
Here, 'user'  is an entity object.which refers to the current portal user, allowing access to all attributes of the underlying CRM contact record. If no user is signed in, this variable will be null.


'has_role'

{% assign is_admin = user | has_role: 'Administrators' %}
{% if is_admin %}
  User is an administrator.
{% endif %}
{% assign is_anonymous = user | has_role: 'Anonymous' %}
{% if is_admin %}
  User is an anonymous .
{% endif %}

Applied to a user object, returns true if the user belongs to the given role. Returns false if not.


By using above two features of ADXStudio, You can achieve all the above mentioned requirements.

I hope you all will get the valuable information, for any query feel free to drop me an email or comment on the post.

Friday 20 January 2017

How to use Fetch XML in ADXStudio Liquid Template

Liquid is an open-source template language integrated into Adxstudio Portals. It can be used add dynamic content to pages, and to create a wide variety of custom templates.

You can learn more about Liquid Template from ADXStudio Community:

https://community.adxstudio.com/products/adxstudio-portals/documentation/configuration-guide/liquid-templates/

In this post I would like to explain, how we can use Fetch XML to retrieve data from CRM in Liquid Template.


  1. {% fetchxml my_query %}
  2.   <fetch version="1.0" mapping="logical">
  3.   <!-- Write FetchXML here, use Liquid in here if you want, to build XML dynamically. -->
  4.   </fetch>
  5. {% endfetchxml %}
  6.  
  7. {{ my_query.xml | escape }}
  8. {{ my_query.results.total_record_count }}
  9. {{ my_query.results.more_records }}
  10. {{ my_query.results.paging_cookie | escape }}
  11. {% for result in my_query.results.entities %}
  12.   {{ result.id | escape }}
  13. {% endfor %}
  14.  
  15. <!-- You can also filter results by Entity Permissions -->
  16. {% fetchxml secure_query enable_entity_permissions: true, right: 'read' %}
  17. {% endfetchxml %}




Note - You must have appropriate Entity Permissions for data to be correctly retrieved. 
For example if you retrieving Contact Entity data using Liquid Template Fetch XML then you must have appropriate Entity Permissions on Contact Entity. (Contact, Account, Parent, Global).

Blogger Widgets