Skip to content

Commit 2ac45f4

Browse files
authored
Fetch field value passed as query parameter from URL and set the value on the field (#1918)
* Create README.md * Create popdatefromurl.js
1 parent 04c6cbd commit 2ac45f4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This piece of code is designed for an usecase where you might want to populate a field value that you're passing as a query in the URL which redirects to a catalog item.
2+
In this case, a custom field 'u_date' is chosen as an example to be shown:
3+
4+
1. You open a catalog item record via a URL that carries a date in the query string.
5+
Example:
6+
https://your-instance.service-now.com/your_form.do?sysparm_u_date=2025-10-31
7+
-(This URL includes a parameter named sysparm_u_date with the value 2025-10-31.)
8+
9+
10+
2. The catalog client script reads the page URL and extracts that specific parameter which returns the value "2025-10-31".
11+
12+
3. If the parameter is present, the script populates the form field.
13+
Calling g_form.setValue('u_date', '2025-10-31') sets the date field on the form to 31 October 2025.
14+
15+
16+
Result:
17+
The date field in the form is prefilled from the URL
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//Logic to fetch the u_date field value passed in the url and setting it in the actual field.
2+
3+
4+
var fetchUrl = top.location.href; //get the URL
5+
6+
var setDate = new URLSearchParams(gUrl).get("sysparm_u_date"); //fetch the value of date from the query parameter
7+
8+
g_form.setValue('u_date', setDate); //set the value to the actual field

0 commit comments

Comments
 (0)