- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 05:10 AM
Hi All,
Is it possible to add default values for a multi row variable set on a catalog form On Load?
Could you please suggest.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 07:01 AM
Your onLoad script was adding an JSON object, but you need to add JSON array (of objects):
function onLoad(){
var objs = [{
"add_application": "9b57780587f6e510273abb3acebb3505"
}];
g_form.setValue('add_applications_for_knowledge_workers', JSON.stringify(objs));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 05:29 AM
Hi @Joshuu ,
Hope you are doing great.
yes , you can add default value for multi row variable set using on load catalog client script.
Use below code for reference :
function onLoad() {
// Get the multi-row variable set field
var multiRowVariableSet = g_form.getControl('variable_set_field_name');
// Check if the multi-row variable set field exists on the form
if (multiRowVariableSet) {
// Retrieve the variable rows within the multi-row variable set
var variableRows = multiRowVariableSet.getMultiRowVariables();
// Iterate through each variable row and set the default values
for (var i = 0; i < variableRows.length; i++) {
var variableRow = variableRows[i];
// Set the default value for each variable within the variable row
variableRow.setValue('variable_field_name', 'default_value');
}
}
}
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 05:37 AM
you can use onLoad catalog client script and set the value using json structure
something like this
function onLoad(){
var obj = {};
obj["variable1Name"] = "your value"; // give your variable name which is inside MRVS and correct value
obj["variable2Name"] = "your value"; // give your variable name which is inside MRVS and correct value
obj["variable3Name"] = "your value"; // give your variable name which is inside MRVS and correct value
g_form.setValue('mrvsVariableSetName', JSON.stringify(obj)); // give mrvs variable set name here
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 05:02 AM - edited 05-29-2023 05:04 AM
Hi @Riya Verma , @Ankur Bawiskar ,
I have tried in both the ways, but it didn't worked for me. Also, here the add application variable is a lookup select box.
Could you please help me, below is my code.
function onLoad(){
var obj = {};
obj["add_application"] = "Office 365 Application"; // give your variable name which is inside MRVS and correct value
g_form.setValue('add_applications_for_knowledge_workers', JSON.stringify(obj)); // give mrvs variable set name here
}
function onLoad() {
// Get the multi-row variable set field
var multiRowVariableSet = g_form.getControl('add_applications_for_knowledge_workers');
// Check if the multi-row variable set field exists on the form
if (multiRowVariableSet) {
// Retrieve the variable rows within the multi-row variable set
var variableRows = multiRowVariableSet.getMultiRowVariables();
// Iterate through each variable row and set the default values
for (var i = 0; i < variableRows.length; i++) {
var variableRow = variableRows[i];
// Set the default value for each variable within the variable row
variableRow.setValue('add_application', 'Office 365 Application');
}
}
}
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 05:16 AM
add_application is reference type?
if yes then please give sys_id and not name
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader