Populate Variables from Existing RITM in a Catalog Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2024 08:44 PM
Hi All,
I have a catalog item (e.g., ABC) with the following requirement:
- There is a variable called Request Type with two options:
- New: Displays a set of variables for submission.
- Old: Displays a reference variable where users can select an existing RITM.(displaying all RITMs submitted for this catalog item)
If the user selects Old and chooses an existing RITM, the variables of the selected ABC RITM should be auto-populated into the current catalog item's variables.
Note: The current variables are part of variable sets, and there are also Multi-Row Variable Sets (MRVS) in the catalog item.
How can I achieve this functionality? Any help or guidance would be appreciated.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2024 08:48 PM
You can try writing a script include that would look up the previous RITM and return the field values that you need to populate the current catalog item request. You can return the set of values as an array and then populate the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2024 08:58 PM
Could you please guide me on how to structure the script and any best practices for achieving this functionality? I would appreciate your expertise and insights on this.
Looking forward to your support.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2024 11:38 PM - edited ‎11-20-2024 11:38 PM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return;
}
var ga = new GlideAjax('Fetchritm');
ga.addParam('sysparm_name', 'fetchRITMVariables');
ga.addParam('sysparm_ritm', newValue); //RITM sys_id
ga.getXMLAnswer(function(response) {
var result = JSON.parse(response);
if (result.success) {
for (var variableName in result.variables) {
g_form.setValue(variableName, result.variables[variableName]);
}
} else {
}
});
}
var Fetchritm = Class.create();
SimpleRITMFetcher.prototype = {
initialize: function() {},
fetchRITMVariables: function() {
var response = { success: false, variables: {} };
try {
var ritmSysId = this.getParameter('sysparm_ritm');
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(ritmSysId)) {
var vars = ritm.variables.getElements();
vars.forEach(function(variable) {
response.variables[variable.getName()] = variable.getDisplayValue();
});
response.success = true;
} else {
response.message = 'not found.';
}
} catch (err) {
response.message = 'Error: '
}
return new JSON().encode(response);
},
type: 'Fetchritm'
};
Edit it Accordingly
If my answer helped you in any way, then mark it as helpful or correct. This will help others finding a solution.
Thanks,
Raj