How to use MRVS variables in catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 09:44 PM - edited 12-04-2023 10:06 PM
I have created MRVS variable (agent_details) in a catalog item. MRVS variables are :
1. agent_name
2. recurring_cost
3. forming_cost
4. entity_name
The requirement is that the forming cost should exceed $1000 considering all records created in this MRVS.
eg. If end user creates first MRVS record as:
['Anthony', 100, 500, 'IT']
Now, when the End user is creating second record in MRVS, then after entering forming_cost, an on_change script should run and the employee should not be able select the forming_cost >500 since already 500 $ is utilized in first record.
Number of records may be multiple.
For this I am trying to write an on_change client script on forming_cost field. I am trying to fetch forming cost but not able to do so:
if( (total + newValue)>1000){
g_form.addInforMessage("Total forming cost exceeding 1000 $");
return false;
}
Note : All calculation will happen before we submit the catalog request or saving the form.
Please suggest the correction or new approach.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 10:31 PM
are you getting the forming cost for the previous rows?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 11:00 PM - edited 12-04-2023 11:53 PM
Hi @Ankur Bawiskar,
Thank you for your time.
No. I tried but no luck.
Actually, I need to fetch the forming cost on the form itself before the catalog request is submitted. But not able to do so.
Please suggest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 12:55 AM
Hello @Asmita7 ,
Let me suggest you a approach which you can try for your implementation, You can write an OnSubmit client script on mvrs with the below script as example:
var formingData = g_form.getValue("formingData");
if(sessionStorage.getItem("data") == null){ //set Value for first time
sessionStorage.setItem("data", formingData);
}else{
var sessionData = sessionStorage.getItem("data");
var total = parseInt(sessionData) + parseInt(formingData);
if(total > 1000){
g_form.addErrorMessage("As total > 1000, please update the value");
return false;
}else{
sessionStorage.setItem("data",total);
}
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.