Use of g_form in a UI Script on Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2018 12:28 PM
All,
My team is working to update our catalog items to function in the Service Portal. Among many hiccups we have found and worked around there is one that is quite frustrating. We have a UI script that has a lot of commonly used functions on our Service Catalog that we call frequently. In the Service Portal there are errors where g_form is undefined/unrecognized when attempting to update the form from the UI Script. Is there a known fix for this?
Thank you,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2018 01:32 PM
I think this can easily be done using a client script.
function onSubmit(){
//Set the mandatory checkbox variable names and total mandatory count here
var mandatoryVars = 'byod_airwatch,pcl,haiku,rover,software_other';
var mandatoryCount = 1;
var passed = forceMandatoryCheckboxes(mandatoryVars, mandatoryCount);
if(!passed){
//Abort the submit
alert('You must select at least ' + mandatoryCount + ' software.');
return false;
}
}
function forceMandatoryCheckboxes(mandatory, count){
//Split the mandatory variable names into an array
mandatory = mandatory.split(',');
var answer = false;
var varFound = false;
var numTrue = 0;
//Check each variable in the array
for(x=0;x<mandatory.length;x++){
//Check to see if variable exists
if(g_form.getControl(mandatory[x])){
varFound = true;
//Check to see if variable is set to 'true'
if(g_form.getValue(mandatory[x]) == 'true'){
numTrue ++;
//Exit the loop if we have reached required number of 'true'
if(numTrue >= count){
answer = true;
break;
}
}
}
}
//If we didn't find any of the variables allow the submit
if(varFound == false){
answer = true;
}
//Return true or false
return answer;
}
If you still want to use UI script, response from Paul in below link should give you the solution
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2018 01:48 PM
Make sure that on the catalog client script the UI type is set to 'Both' or g_form will not be accessible. Just to be safe I set the 'Availability' field on the catalog item to 'Desktop and Mobile' as well.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2024 02:43 PM
Hi Ilo,
have you tried to handover the g_form object to your function in the UI script? Then it should work.
HTH,
Heiko