Skip to content

Commit 4cb3952

Browse files
authored
Open Record producer from Workspace and auto-populate data on the opened record producer (#1546)
* Create readme.md * Create OpenRecordProducer.js * Create ParseUrl.js * Update readme.md * Update ParseUrl.js * Update readme.md * Update ParseUrl.js
1 parent 2724cfe commit 4cb3952

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
UI Action
3+
Client - true
4+
action name - open_item
5+
show update - true ( As per your requirement)
6+
onClick - openItem();
7+
Workspace Form button - true
8+
Format for Configurable Workspace - true
9+
*/
10+
11+
//Workspace client script:
12+
function onClick() {
13+
var result = g_form.submit('open_item');
14+
if (!result) {
15+
return;
16+
}
17+
result.then(function() {
18+
var params = {};
19+
params.sysparm_parent_sys_id = g_form.getUniqueValue();
20+
params.sysparm_shortDescription = g_form.getValue('short_description');
21+
//add params as required, These params can be parsed and used in the record producer.
22+
g_service_catalog.openCatalogItem('sc_cat_item', 'recordproducer_sysid_here', params);
23+
//Use the record producer sys_id in second parameter.
24+
});
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Catalog Client script on the record producer/catalog item you want to open from ui action
3+
Name - ParseURL
4+
Type - Onload
5+
Applies on catalog item view - true
6+
*/
7+
8+
function onLoad() {
9+
10+
11+
g_form.setValue('task',parseURL('sysparm_parent_sys_id'));
12+
g_form.setValue('description',parseURL('sysparm_description));
13+
14+
function parseURL(paramName) {
15+
16+
var url = decodeURIComponent(top.location.href); //Get the URL and decode it
17+
var workspaceParams = url.split('extra-params/')[1]; //Split off the url on Extra params
18+
var allParams = workspaceParams.split('/'); //The params are split on slashes '/'
19+
20+
//Search for the parameter requested
21+
for (var i=0; i< allParams.length; i++) {
22+
if(allParams[i] == paramName) {
23+
return allParams[i+1];
24+
}
25+
}
26+
}
27+
}
28+
/*
29+
pass the parameter name which was used in the ui action to parse the value here.
30+
Example - parseURL('sysparm_description) as I am passing description value in the params from ui action.
31+
*/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
When we want to open a catalog item with details from current record and map it to the opened catalog form then we can use this code.
2+
3+
This UI Action and catalog client script Redirects you to the record producer or catalog item( based on the sys id provided) and auto-populates the fields from the parent record to the catalog item/record producer variables.
4+
5+
1. UI Action
6+
Client - true
7+
action name - open_item
8+
show update - true ( As per your requirement)
9+
onClick - openItem();
10+
Workspace Form button - true
11+
Format for Configurable Workspace - true
12+
13+
2. Catalog Client script.
14+
Type - Onload
15+
Applies on catalog item view - true
16+
Name - ParseURL
17+
18+
Note : Above UI Action works in Configurable workspace and opens the catalog item/record producer in workspace itself.

0 commit comments

Comments
 (0)