Skip to content

A new catalog client script #1068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function onLoad() {

var taskId = getParameterValue("taskid");

if (taskId != "" && taskId != null && taskId != undefined) {
console.log('=== CAMACHO Task id: ' + taskId);

var gaGetTaskNumber = new GlideAjax('UtilsAjax');
gaGetTaskNumber.addParam('sysparm_name', 'getTaskNumber');
gaGetTaskNumber.addParam('sysparm_task_id', taskId);
gaGetTaskNumber.getXMLAnswer(setmyFormValue);
}
}

function setmyFormValue(answer) {

//console.log('=== CAMACHO Entered setmyFormValue');
if (answer) {
var obj = JSON.parse(answer);
var numero = obj.number.toString();
console.log(numero);

g_form.setValue('task_number', numero);

}
}

function getParameterValue(name) {
var url = top.location.href;
var value = new URLSearchParams(url).get(name);
if (value) {
return value;
} else {
return null;
}
}
37 changes: 37 additions & 0 deletions Catalog Client Script/Set fields from URL Parameter 2/KMXOUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var KMXOUtils = Class.create();
KMXOUtils.prototype = {
initialize: function() {
},

/*
* Receives a um sys_id and returns a Task table field value
*
* @param {String} - taskId
* @return {Object}
*/
getTaskNumber: function(taskId)
{
if (taskId != "" && taskId != null && taskId != undefined) {

var grTask = new GlideRecord('x_770214_consultor_rwd_activity');

if (grTask.get(taskId)) {

var number = grTask.getValue('number');

var obj = {};
obj["number"] = number;

return obj;

} else {

return {};

}

}
},

type: 'KMXOUtils'
};
11 changes: 11 additions & 0 deletions Catalog Client Script/Set fields from URL Parameter 2/UtilsAjax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var UtilsAjax = Class.create();
UtilsAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

getTaskNumber: function() {
var taskId = this.getParameter('sysparm_task_id');
gs.debug('=== Camacho UtilsAjax = Received the sys_id ' + taskId);
return JSON.stringify(new KMXOUtils().getTaskNumber(taskId));

},
type: 'UtilsAjax'
});
27 changes: 27 additions & 0 deletions Catalog Client Script/Set fields from URL Parameter 2/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Set fields on a catalog item from URL parameters.

The mission was to get a sys_id from the URL, query a record and return a value to the front-end.

In the front-end we have a Record Producer (RP) with a String field.

On the onLoad event, we want to populate the field in order to show the value retrieved from the back-end.

The Use Case is defined so let's go to the step by step process.

1. Create a Util class in the back-end

Our Utils class will be a Script Include that receives a sys_id and returns a String.

[KMXOUtils](KMXOUtils.js)

2. Create a class to provide access for the Front-End

2.1. To provide access in this class, the parameter Client callable should be True (checked)

[UtilsAjax](UtilsAjax.js)

3. I'll suppose that you have a String field called task_number in your RP

3.1. Create a Catalog Client Script (Type: OnLoad) to get the URL parameter and call the back-end class:

[CatalogClientScript](CatalogClientScript.js)
Loading