- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2024 11:55 PM
Hi Team,
function () { [native code] }
Front of portal it's setting the variable value in below image
could pls help to resolve this error
Advance thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2024 01:11 AM
As far as I know g_scratchpad is not supported in CMS - only in Portal.
A workaround could be "simulating" it, something like:
function onSubmit () {
var scratchpad = getExistingScratchpad() || getCustomScratchpad();
if (scratchpad.validForm) {
return;
}
var reason1 = g_form.getValue('reason1');
var reason2 = g_form.getValue('reason2');
var mrvs = g_form.getValue('risk_rating_from_country');
var vk = new GlideAjax("Decision_table_risk_rating");
vk.addParam('sysparm_name', 'getriskratings');
vk.addParam('sysparm_from', g_form.getValue('from'));
vk.addParam('sysparam_to', g_form.getValue('to'));
vk.addParam('sysparam_mrvs', mrvs);
vk.getXML(function risk (response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('risk rating' + answer);
g_form.setValue('risk_rating', answer);
if (answer == 1 && reason1 == '' && reason2 == '') {
g_form.setVisible('reason1', true);
g_form.setVisible('reason2', true);
g_form.setMandatory('reason1', true);
g_form.setMandatory('reason2', true);
scratchpad.validForm = false;
}
else {
scratchpad.validForm = true;
g_form.submit();
}
});
return false;
function getCustomScratchpad () {
return NOW.g_scratchpad = NOW.g_scratchpad || {};
}
function getExistingScratchpad () {
if (typeof g_scratchpad != 'undefined')
return g_scratchpad;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2024 01:11 AM
As far as I know g_scratchpad is not supported in CMS - only in Portal.
A workaround could be "simulating" it, something like:
function onSubmit () {
var scratchpad = getExistingScratchpad() || getCustomScratchpad();
if (scratchpad.validForm) {
return;
}
var reason1 = g_form.getValue('reason1');
var reason2 = g_form.getValue('reason2');
var mrvs = g_form.getValue('risk_rating_from_country');
var vk = new GlideAjax("Decision_table_risk_rating");
vk.addParam('sysparm_name', 'getriskratings');
vk.addParam('sysparm_from', g_form.getValue('from'));
vk.addParam('sysparam_to', g_form.getValue('to'));
vk.addParam('sysparam_mrvs', mrvs);
vk.getXML(function risk (response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('risk rating' + answer);
g_form.setValue('risk_rating', answer);
if (answer == 1 && reason1 == '' && reason2 == '') {
g_form.setVisible('reason1', true);
g_form.setVisible('reason2', true);
g_form.setMandatory('reason1', true);
g_form.setMandatory('reason2', true);
scratchpad.validForm = false;
}
else {
scratchpad.validForm = true;
g_form.submit();
}
});
return false;
function getCustomScratchpad () {
return NOW.g_scratchpad = NOW.g_scratchpad || {};
}
function getExistingScratchpad () {
if (typeof g_scratchpad != 'undefined')
return g_scratchpad;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2024 02:30 AM
Thanks for your ans @-O-
But if i use this script in the last function it's showing one message like can't find the g_scratchpad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2024 02:32 AM
This kind of message i am getting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2024 02:40 AM
After using your script its working but in TRY IT UI action it's showing one error message bro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2024 03:39 AM
So when you are using the Try It button on the Catalog Item form, it opens the Catalog Item in the old legacy CMS environment.
Not Portal.
And those environments are vastly different when it comes to supported APIs.
Thus g_form.submit() is valid in Portal, but not in CMS (Content Management System).
Vice-versa g_form.orderNow() is valid in CMS, but not in Portal.
The right solution for this is to create separate onSubmit Catalog Client Scripts per environment.
One does that by setting field "UI Type" on the "Catalog Client Script" form:
If UI Type is "Desktop" or "All" the Catalog Client Script will be executed in CMS.
If UI Type is "Mobile / Service Portal" or "All" the Catalog Client Script will be executed in Portal.
So in the "Desktop" variant of the onSubmit Catalog Client Script you would use
g_form.orderNow()
but in the "Mobile / Service Portal" variant of the onSubmit Catalog Client Script you would use
g_form.submit()