Populate catalog item fields from the values stored in a custom table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 05:12 AM
I have a catalog item with a date field and another text field.
The requirement is that when a requestor opens the catalog item then based on the date field value it should fetch the values from another table that contains this data for the requestor.
for example, the table "ABC" has the following data stored.
Username = "Test User"
Date = 31-08-2022
ID = 123
so what is needed is that when the requestor "Test User" opens the catalog item and selects the date as 31-08-2022 the other fields on the catalog item should populate the values stored in the table ABC for this date and this user.
so if the requestor selects the date 31-08-2022 the field u_ID on the catalog item should auto-populate from the ID field in the ABC table.
Any help would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 03:24 AM
Share both the scripts here and not the screenshots.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 03:33 AM
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var request = g_form.getValue('name');
var date = g_form.getValue('date_day');
//alert('date '+date + ' requested ' + request );
var ajax = new GlideAjax('dateformat');
ajax.addParam('sysparm_name', 'getdate');
ajax.addParam('sysparm_req', request);
ajax.addParam('sysparm_date', date);
ajax.getXMLWait();
var answer = ajax.getAnswer();
// alert("current date" + answer);
g_form.setValue('ssp_code', answer);
}
Script Include:
var dateformat = Class.create();
dateformat.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getdate: function() {
var req = this.getParameter('sysparm_req');
var date = this.getParameter('sysparm_date');
//gs.log('date ' + date + ' requested ' + req);
var gd = new GlideRecord('x_sosb_fico_time_c_recorded_on_entries');
gd.addQuery('u_name', req);
gd.addQuery('date_day', date);
gd.query();
if (gd.next()) {
var id = gd.ssp_code;
}
return id;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 03:57 AM
Hi,
both script include and client scripts are in same scope?
update as this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var request = g_form.getValue('name');
var date = g_form.getValue('date_day');
var ajax = new GlideAjax('dateformat');
ajax.addParam('sysparm_name', 'getdate');
ajax.addParam('sysparm_req', request);
ajax.addParam('sysparm_date', date);
ajax.getXMLAnswer(function(answer){
g_form.setValue('ssp_code', answer);
});
}
Script Include:
var dateformat = Class.create();
dateformat.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getdate: function() {
var req = this.getParameter('sysparm_req');
var date = this.getParameter('sysparm_date');
var gd = new GlideRecord('x_sosb_fico_time_c_recorded_on_entries');
gd.addQuery('u_name', req);
gd.addQuery('date_day', date);
gd.query();
if (gd.next()) {
var id = gd.ssp_code;
return id;
}
return '';
}
});
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2022 03:12 AM
can you share your complete script here?
Also what's the field type for Date/Day in your table?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 04:30 AM
Hello Suryansh,
I have used getXMLWait(); that's why it's not working in the portal. Please use following updated code.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var request = g_form.getValue('requested_for');
var date = g_form.getValue('date');
// alert('date ' + date + ' requested ' + request);
var ajax = new GlideAjax('dateformat');
ajax.addParam('sysparm_name', 'getdate');
ajax.addParam('sysparm_req', request);
ajax.addParam('sysparm_date', date);
ajax.getXMLAnswer(setAnswer);
function setAnswer(answer) {
// alert("current date" + answer);
g_form.setValue('id', answer);
}
}
Regards,
Akshay