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-17-2022 05:55 AM
Hello Suryansh,
What is type of field Date on catalog item? Is it date type field?
Regards,
Akshay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 06:07 AM
Hello
Thank you for responding and yes it is a date type field on both the catalog item and the table also.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 06:48 AM
Hello
Thanks for the clarification. Your requirement can be achieved using onchange client script and script include. I have created one example, PFB screen shot.
Onchange client script -
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.getXMLWait();
var answer = ajax.getAnswer();
// alert("current date" + answer);
g_form.setValue('id', answer);
}
Script include -
code -
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('incident');
gd.addQuery('caller_id', req);
gd.addQuery('u_issue_since', date);
gd.query();
if (gd.next()) {
var id = gd.short_description;
}
return id;
}
});
Catalog form -
Kindly note that I have added my variables for testing, please user your variable names correctly.
Regards,
Akshay Kangankar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 03:21 AM
Thanks,
I have implemented the same but getting errors when selecting the date on the catalog item.
"There is a JavaScript error in your browser console"