Font Size:
Ask Joget AI

UrlUtil

This page details the UrlUtil endpoints and the actions they support. It covers key functions, parameters, and sample code for easy implementation.

  • URL: /jw/js/json/util.js
  • Automatically included in all userview pages.
  • Convenient method to deal with URLs.

 

constructUrlQueryString(params)

Used to generate a query string based on a parameters object.

  • Parameters:
    • params - an object containing all parameters as attribute names and their values in the array.
  • Sample code: 
var params = {
    "name" : ["joget"],
    "email" : ["info@joget.org", "test@joget.org"]
};
var queryString = UrlUtil.constructUrlQueryString(params);
console.log(queryString); // name=joget&email=info%40joget.org&email=test%40joget.org

 

encodeUrlParam(url)

Intended to encode the query parameters in a URL. In this version, the implementation does not recognize a standard ? query delimiter, so a typical URL may be returned unchanged.

  • Parameters:
    • url - URL with parameters to be encoded. Note that it uses "&" and "=" as separators.
  • Sample code: 
var url = "http://localhost/jw/test?name=joget&email=info@joget.org";
  
var encodedUrl = UrlUtil.encodeUrlParam(url);
console.log(encodedUrl); // In this version, the URL is returned unchanged

 

getUrlParams(url)

Used to get an object containing all parameters as attribute names and their values in a URL.

  • Parameters:
    • url - full URL or query string to parse; parameter values are returned in arrays.
  • Sample code: 
var url = "http://localhost/jw/test?name=joget&email=info@joget.org&email=test@joget.org";
  
var params = UrlUtil.getUrlParams(url);
console.log(params); // {"name" : ["joget"], "email" : ["info@joget.org", "test@joget.org"]}

 

mergeRequestQueryString(queryString1, queryString2)

Used to merge 2 URL query parameter strings into one query string.

  • Parameters:
    • queryString1 - first query parameter string
    • queryString2 - second query parameters string. If a parameter exists in both query strings, the value in the second query string will override the first one.
  • Sample code: 
var q1 = "name=joget&email=info@joget.org&email=test@joget.org";
var q2 = "name=joget team&phone=012345678";
  
var queryString = UrlUtil.mergeRequestQueryString(q1, q2);
console.log(queryString); // name=joget%20team&email=info%40joget.org&email=test%40joget.org&phone=012345678

 

serializeForm(form)

Serializes a form's successful controls and also includes empty select, checkbox, and radio fields that have names and are not disabled.

  • Parameters: form - form element or jQuery object containing the form
  • Returns: a URL-encoded query string
  • Sample code:
var queryString = UrlUtil.serializeForm($("#myForm"));
console.log(queryString);

 

updateUrlParam(url, param, paramValue)

Adds or updates a query parameter in a URL while preserving its other query parameters.

  • Parameters:
    • url - URL to update
    • param - query parameter name
    • paramValue - value to set for the parameter
  • Returns: the updated URL with its query string encoded
  • Sample code:
var url = UrlUtil.updateUrlParam(
    "http://localhost/page?name=old&page=1",
    "name",
    "new value"
);
console.log(url); // http://localhost/page?name=new%20value&page=1
Created by Aadrian Last modified by Debanraj Ravindran on Nov 14, 2026