Getting the URL parameter values in client script

Getting the params value from the URL in the client script and perform the actions

Syntax:

function pageInit(scriptContext) {

    window.onbeforeunload = null;

    //Getting parameter value from URL

    let urlParams = new URLSearchParams(window.location.search);

    let employeeId= urlParams.get(’empId’);

    let record = scriptContext.currentRecord;

    record.setValue({

      fieldId: ‘custpage_jj_employee_id’,

      value: employeeId

    });

}

Explanation:

  1. window.location-> Object return the string of the current URL
  2. URLSearchParams-> Built-in JS interface method work with the string of the URL
  3. let employeeId= urlParams.get(’empId’); -> Can get the employeeId value from parameter

Leave a comment

Your email address will not be published. Required fields are marked *