- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2023 02:26 PM
Here's another way to do it.
- Create a UI page and add the following code to it:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My UI Page</title>
<script>
function passData() {
var data = {
"field1": "value1",
"field2": "value2"
};
var url = "/nav_to.do?uri=incident.do?sys_id=-1&sysparm_query=";
var encodedData = encodeURIComponent(JSON.stringify(data));
url += encodedData;
window.location.href = url;
}
</script>
</head>
<body>
<h1>My UI Page</h1>
<button onclick="passData()">Pass Data</button>
</body>
</html>
This code defines a function passdata( ) that creates a data object and encodes it as a URL parameter. When the user clicks the "Pass Data" button, the function sets the current URL to the URL of a new incident form with the encoded data added as a parameter.
- Create a UI action that opens the UI page you just created:
(function() {
var url = '/sys_ui_page.do?sys_id=<UI_PAGE_SYS_ID>';
action.setRedirectURL(url);
})();
Replace <UI_PAGE_SYS_ID>with the sys ID of the UI page you created in step 1.
When the user clicks the UI action, the UI page will open, and the "Pass Data" button will be visible. When the user clicks the "Pass Data" button, they will be redirected to a new incident form with the data encoded as a parameter in the URL. You can retrieve this data in the new form using a script like this:
var urlParams = new URLSearchParams(window.location.search);
var encodedData = urlParams.get('sysparm_query');
var data = JSON.parse(decodeURIComponent(encodedData));
Please mark my answer correct/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal. Thanks, Punit