Forums

Forums / Developing Portals / Read Parameter from a URL

Read Parameter from a URL

Thread is closed for posting
2 posts, 1 answered
  1. clefsrud
    clefsrud avatar
    26 posts
    Registered:
    24 Nov 2014
    17 Jun 2016
    Link to this post
    We have a portal form which is accessed only via an externally prepared url, which defines a number of specific guid values; these values are submitted with the form to create an appropriate record in CRM.
    I wish to add another parameter (bit value) to the url which will not be included in the data submitted back to CRM.  The value will be used solely to determine the visibility of certain data entry field controls on the form.  Controlling the fields is easy enough, but I cannot get my logic/form to 'read' the bit value from the url.  I have attempted to replicate the handling of the other url parameters with no success.
    Is this possible? How?
  2. Clinton Bale
    Clinton Bale avatar
    126 posts
    Registered:
    21 Feb 2014
    Answered
    21 Jun 2016 in reply to clefsrud
    Link to this post
    Hello Chris,

    I have attached some JavaScript similar to what we have used in the past to read the query string. Also included is an example of how to split logic, hide fields or disable fields using our API:

    var queryString;
    (window.onpopstate = function () {
        var match,
            pl     = /\+/g,  // Regex for replacing addition symbol with a space
            search = /([^&=]+)=?([^&]*)/g,
            decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
            query  = window.location.search.substring(1);
    
        queryString = {};
        while (match = search.exec(query))
           queryString[decode(match[1])] = decode(match[2]);
    })();
    $(document).ready(function(){
      var show = queryString["bitValue"] == "true";
      if(show) {
        $(".CrmTextField_C004").hide();
        $(".CrmTextField_C005").hide();
        $(".CrmTextField_C006").hide();  
      }
      else {
        $(".CrmTextField_C001").hide();
        $(".CrmTextField_C002").hide();
        $(".CrmTextField_C003").hide();
        // if you want the field not to be submitted to CRM:
        findControl(".CrmTextField_C001").disable();
      }
    });
    

    Please let me know if you have any questions.

    Regards,
    Clinton
2 posts, 1 answered