Set Value on MVRS from the catalog form variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 03:24 AM
Hello All,
Thanks for looking into the ask,
We have a catalog variable : Applications(list collector)
We have a mvrs: which has Applications(reference) field.
We need to create and set, each row for the applications selected on the Catalog form variable Application(list collector) on to the MVRS.
Any feedback on the same will be highly appreciable.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 03:43 AM - edited 07-01-2024 03:44 AM
Hi @Kaustubh k ,
This can be achieved through catalog client scripts.
Can I know what is the structure of your MRVS, and give me a brief sense of how / on which variable(s) you want the values selected from list collector to be mapped. So that I can help further.
Regards,
Bhavani Shankar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 04:01 AM - edited 07-01-2024 04:02 AM
Thanks @Bhavani Shankar for looking in to the ask,
There is a field list collectors which allows multiple selections for Application on the catalog form;
Select the application:(ABC,EFG..)
We have a MVRS;
With fields;
Application name Application Owner
1.ABC XYZ
2.EFG QRS
The ask was to make the field on MVRS auto populate with the values on the Catalog form Variable(list collector).
eg: for Applications: ABC and EFG of the List collector we need to have two entries on the MVRS created as shown above.
hope this clarifies the asks.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 04:12 AM
Hi @Kaustubh k ,
You need to create a Script include and client script to handle this-
Script include-
var MVRSRecordCreator = Class.create();
MVRSRecordCreator.prototype = {
initialize: function() {},
createRecords: function(applications) {
var appList = applications.split(',');
for (var i = 0; i < appList.length; i++) {
var app = appList[i];
var mvrs = new GlideRecord('sc_multi_row_question_answer'); //Replace if different table
mvrs.initialize();
mvrs.setValue('application_name', app); // Replace 'application_name' with your MVRS field name
mvrs.setValue('application_owner', 'default_owner'); // Set the default owner or get this value dynamically
mvrs.insert();
}
return 'success';
},
type: 'MVRSRecordCreator'
};
Calatog Client Script-
function onSubmit() {
var applicationList = g_form.getValue('applications'); //your list collector variable name
if (applicationList) {
var ga = new GlideAjax('MVRSRecordCreator');
ga.addParam('sysparm_name', 'createRecords');
ga.addParam('sysparm_applications', applicationList);
ga.getXMLAnswer(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer !== 'success') {
g_form.addErrorMessage('Failed to create MVRS records.');
return false;
}
});
}
return true;
}
Note- script include should be client callable.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 06:23 AM
Hello @Community Alums ,
Thanks for replying ,
The code is not working and SI is not getting triggered on Change and there is no records created in sc_multi_row_question_answer.
Updated the SI and catalog client script created on catalog item and type on change of application variable(list collector).
if you can please have a review once and let me know for any issues here tried some approaches but no luck on this.
as Below
And the related script include client callable;
Thanks