GlideAjax question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 09:48 PM
I want to write a client script which will perform some actions (display alert that number or date is empty ) in catalog item when the number and date fields from table xyz .
For this GlideAjax script should be written which should check on the records and return some flag if one of fields in empty.
i want to know how to achieve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 10:50 PM
What is the question?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 10:57 PM
can you share the script on how to achieve this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 11:17 PM - edited 07-11-2024 11:20 PM
Create a new Script Include in the sys_script_include table with client_callable field as true.
---Sample script structure---
---Sample client call script---
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 11:44 PM
Hi @tanz
I didn't completely understand your question. From what I gather, you want to use GlideAjax in a client script to set values in a list collector field
You can refer below code and try to modify it as per your requirement.
Client Script:
function onLoad() {
var openedForValue = g_form.getValue('opened_for');
if (openedForValue) {
var ga = new GlideAjax('MyScriptInclude');
ga.addParam('sysparm_name', 'getSerialNumbers');
ga.addParam('sysparm_opened_for', openedForValue);
ga.getXMLAnswer(function (answer) {
if (answer) {
var serialNumbers = answer.split(',');
g_form.setValue('serial_numbers', serialNumbers.join(','));
}
});
}
}
Client Callable Script Include:
var MyScriptInclude = Class.create();
MyScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSerialNumbers: function () {
var openedForSysId = this.getParameter('sysparm_opened_for');
var serialNumbers = [];
var gr = new GlideRecord('alm_asset');
gr.addQuery('assigned_to', openedForSysId);
gr.query();
while (gr.next()) {
serialNumbers.push(gr.serial_number.toString());
}
return serialNumbers.join(',');
},
type: 'MyScriptInclude'
});
If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.
Best Regards,
Krushna Birla