- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 03:49 AM
Hello Everyone,
We have the requirement where there are variables like Project start date and end date and also, Work package start date and end date on the main form. And, on the MRVS we have only Work package start date and End date.
Now, the work package start date and end date on the MRVS, should depend on the project start date and end date of the main form.
Is there any Possibilities to create OnChange Client script for Multiple Row Variable set depending on the main Catalog Item?
Can anyone please help with this?
Thanks and Regards,
Kruthika
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 06:18 AM
You can simply use g_service_catalog.parent.getValue... to get the main form variable values in an MRVS script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2023 10:22 AM
So your onChange script would look more like this now to only run for one specific Catalog Item:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var catitem = '';
if (this) { //Service Portal method
catitem = this.cat_g_form.getUniqueValue();
} else { //native UI method
catitem = parent.g_form.getUniqueValue();
}
if (catitem == '964185f78726a9100b25986d3fbb35c1') { //replace with the sysid of your Catalog Item
var ProjectStartDate = g_service_catalog.parent.getValue('value of project start date of catalog item');
var ProjectEndDate = g_service_catalog.parent.getValue(‘value of project end date of catalog item');
var WorkPackageStartDate = g_form.getValue(‘MRVS wrkpckgestart date’);
if (ProjectStartDate != '' && ProjectEndDate != '') {
if(!((WorkPackageStartDate >= ProjectStartDate) && (WorkPackageStartDate <= ProjectEndDate))) {
g_form.addErrorMessage("Please enter the dates in between Your Project Start Date and Project End Date i.e " +ProjectStartDate+" and "+ProjectEndDate);
g_form.clearValue((‘MRVS wrkpckgestart date’);
}
} else {
g_form.addErrorMessage('Please Enter Project Start Date and Project End Date');
g_form.clearValue((‘MRVS wrkpckgestart date’);
}
}
}
then create an onLoad Catalog Client Script that applies to the Catalog Item:
function onLoad() {
if (this) { // only needed for Service Portal
// make the g_form object for the parent item available from the MRVS window
this.cat_g_form = g_form;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 06:54 AM
HI @Kruthika BM ,
I trust you are doing great.
Here's an example of how you can implement the onChange client script for the MRVS fields:
function onChangeWorkPackageDates() {
// Get the project start and end dates from the main form
var projectStartDate = g_form.getValue('project_start_date');
var projectEndDate = g_form.getValue('project_end_date');
// Get the MRVS fields
var workPackages = g_form.getControl('work_packages')._container.childNodes;
// Loop through each MRVS row
for (var i = 0; i < workPackages.length; i++) {
var workPackage = workPackages[i];
// Update the work package start and end dates
var workPackageStartDate = workPackage.querySelector('[name$="start_date"]');
var workPackageEndDate = workPackage.querySelector('[name$="end_date"]');
workPackageStartDate.value = projectStartDate;
workPackageEndDate.value = projectEndDate;
}
}
To implement this solution:
- Navigate to the form where you have the project start and end dates and the MRVS.
- Open the client script section for that form.
- Create a new client script and choose the appropriate conditions for when it should run (e.g., catalog item or variable set).
- In the script, use the provided code snippet and customize it based on your field names and form structure.
- Save the client script.
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 04:52 AM
Hello Amit,
Thank you for the quick support by providing the clear steps.
I tried with this syntax and it worked - g_service_catalog.parent.getValue
Regards,
Kruthika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2023 03:47 AM
Hello @Brad Bowman ,
Hope you are doing good!
Since, the MRVS is included for 2 catalog items, the client script which we created is affecting the other catalog item as well. Do we have any other way to implement this requirement which will apply for only one of the catalog item?
Thanks in Advance!
Regards,
Kruthika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2023 06:00 AM - edited 08-02-2023 10:10 AM
You can get the sys_id of the Catalog Item using this syntax, then add an if condition to only run the script if it matches the one Catalog Item that you want:
var catitem = parent.g_form.getUniqueValue();
This syntax works in the native UI. If you are using Service Portal / Employee Center you need to add an onLoad Catalog Client Script that applies to the Catalog Item itself, not the MRVS:
function onLoad() {
if (this) { // only needed for Service Portal
// make the g_form object for the parent item available from the MRVS window
this.cat_g_form = g_form;
}
}
Then this part of the MRVS script would look more like this to work for both interfaces:
var catitem = '';
if (this) { //Service Portal method
catitem = this.cat_g_form.getUniqueValue();
} else { //native UI method
catitem = parent.g_form.getUniqueValue();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2023 08:28 AM
@Brad Bowman Thank you for the quick help!
Could you please elaborate more in the single script?
We are using the Service Portal/ Employee center.
Thanks and Regards,
Kruthika