Skip to content

Commit 3149aef

Browse files
kmxokmxo
andauthored
A new catalog client script (#1068)
* URL Parameter Use Case * update background scripts folder * fixing --------- Co-authored-by: kmxo <[email protected]>
1 parent 01a30a8 commit 3149aef

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function onLoad() {
2+
3+
var taskId = getParameterValue("taskid");
4+
5+
if (taskId != "" && taskId != null && taskId != undefined) {
6+
console.log('=== CAMACHO Task id: ' + taskId);
7+
8+
var gaGetTaskNumber = new GlideAjax('UtilsAjax');
9+
gaGetTaskNumber.addParam('sysparm_name', 'getTaskNumber');
10+
gaGetTaskNumber.addParam('sysparm_task_id', taskId);
11+
gaGetTaskNumber.getXMLAnswer(setmyFormValue);
12+
}
13+
}
14+
15+
function setmyFormValue(answer) {
16+
17+
//console.log('=== CAMACHO Entered setmyFormValue');
18+
if (answer) {
19+
var obj = JSON.parse(answer);
20+
var numero = obj.number.toString();
21+
console.log(numero);
22+
23+
g_form.setValue('task_number', numero);
24+
25+
}
26+
}
27+
28+
function getParameterValue(name) {
29+
var url = top.location.href;
30+
var value = new URLSearchParams(url).get(name);
31+
if (value) {
32+
return value;
33+
} else {
34+
return null;
35+
}
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var KMXOUtils = Class.create();
2+
KMXOUtils.prototype = {
3+
initialize: function() {
4+
},
5+
6+
/*
7+
* Receives a um sys_id and returns a Task table field value
8+
*
9+
* @param {String} - taskId
10+
* @return {Object}
11+
*/
12+
getTaskNumber: function(taskId)
13+
{
14+
if (taskId != "" && taskId != null && taskId != undefined) {
15+
16+
var grTask = new GlideRecord('x_770214_consultor_rwd_activity');
17+
18+
if (grTask.get(taskId)) {
19+
20+
var number = grTask.getValue('number');
21+
22+
var obj = {};
23+
obj["number"] = number;
24+
25+
return obj;
26+
27+
} else {
28+
29+
return {};
30+
31+
}
32+
33+
}
34+
},
35+
36+
type: 'KMXOUtils'
37+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var UtilsAjax = Class.create();
2+
UtilsAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
3+
4+
getTaskNumber: function() {
5+
var taskId = this.getParameter('sysparm_task_id');
6+
gs.debug('=== Camacho UtilsAjax = Received the sys_id ' + taskId);
7+
return JSON.stringify(new KMXOUtils().getTaskNumber(taskId));
8+
9+
},
10+
type: 'UtilsAjax'
11+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Set fields on a catalog item from URL parameters.
2+
3+
The mission was to get a sys_id from the URL, query a record and return a value to the front-end.
4+
5+
In the front-end we have a Record Producer (RP) with a String field.
6+
7+
On the onLoad event, we want to populate the field in order to show the value retrieved from the back-end.
8+
9+
The Use Case is defined so let's go to the step by step process.
10+
11+
1. Create a Util class in the back-end
12+
13+
Our Utils class will be a Script Include that receives a sys_id and returns a String.
14+
15+
[KMXOUtils](KMXOUtils.js)
16+
17+
2. Create a class to provide access for the Front-End
18+
19+
2.1. To provide access in this class, the parameter Client callable should be True (checked)
20+
21+
[UtilsAjax](UtilsAjax.js)
22+
23+
3. I'll suppose that you have a String field called task_number in your RP
24+
25+
3.1. Create a Catalog Client Script (Type: OnLoad) to get the URL parameter and call the back-end class:
26+
27+
[CatalogClientScript](CatalogClientScript.js)

0 commit comments

Comments
 (0)