UI Page Glide

joeowen
Kilo Explorer

I am currently using a UI Page to hold a form in which values are passed. The UI Page that I am using is public as it is like a support system so people do not have to login. When using new GlideRecord in the client script it seems like it is not allowing public users to get information from the system. An example of this is that I am using dropdown boxes for categories and then populating a sub-category dropdown depending on the category etc. I have tried making the ACL read for the cat and sub-cat tables public but it is also having problems. Here is the snippet of the code I am using. When I am logged in by the way the fields populate perfectly.

function updateSubCat(elem) {

            var optionValue = elem.options[elem.selectedIndex].value; // Gets the sys_id selected category

            removeOptions(); // Removes existing sub-category options

            var item = new GlideRecord('u_sub_categories'); // Creates a new glide record for u_sub_categories

            item.addQuery('u_parent', optionValue); // Adds the sys_id of the selected category to the query as parent

            item.orderBy('u_sub_category'); // Order the results by sub-category

            item.query(); // query the record

            // Loop through each record and add to the dropdown list

            while(item.next()){

                      var y = document.getElementById("u_sub_category"); // Gets the sub-category dropdown

                      var yoption = document.createElement("option"); // Creates an option for the dropdown

                      yoption.text = item.u_sub_category; // Sets the display value to the sub-category

                      yoption.value = item.sys_id; // Sets the value of the field to the sys_id of the category

                      y.add(yoption); // Adds the option to the list

}                            

            // Checks whether the value is equal to the sys_id of the category Other

            if(optionValue == "12719803994a31007f448829d69a5701"){

                      document.getElementById("tbl_sub_cat").style.display = "none"; // If yes it will hide the sub-category field

                      var y = document.getElementById("u_sub_category"); // Finds the select element for sub-category

                      y[0].setAttribute("selected","selected"); // Sets the default selected to the "Other" sub-category

            } else {

                      document.getElementById("tbl_sub_cat").style.display = "inline"; // If it is not it will set the field to be displayed.

            }

}

I am also having a problem submitting the data into a table. Any help would be greatly appreciated.

11 REPLIES 11

joeowen
Kilo Explorer

Bump


syed_faheem
ServiceNow Employee
ServiceNow Employee

Hi I have the same problem, have you been able to resolve this issue ?


No unfortunately. Only problem with ServiceNow is it makes it difficult/challenging to do these sort of things.


syed_faheem
ServiceNow Employee
ServiceNow Employee

I was able to resolve this issue by an Ajax call to script include.



The reason glide query does not work from UI page Client Script is that it does not have sufficient access to the table. When you develop the script include you need to explicitly set its access to public.



See below script include which i developed:



var Customer_Approval_Util_Public = Class.create();


Customer_Approval_Util_Public.prototype = Object.extendsObject(AbstractAjaxProcessor, {


update_record: function()


{


//gs.log('glideajax '+this.getParameter('sysparm_c_sys_id'),'syed');


var grCharges = new GlideRecord('u_customer_approval');


grCharges.get(this.getParameter('sysparm_c_sys_id'));


grCharges.u_approval_decision=this.getParameter('sysparm_c_decsion');


grCharges.update();


return "updated";


},


isPublic: function() {


    return true;


  },


type : "Customer_Approval_Util_Public"


});



and then this is how you would call it from client script.



var CA_Util = new GlideAjax('Customer_Approval_Util_Public');


CA_Util.addParam('sysparm_name','update_record');


CA_Util.addParam('sysparm_c_sys_id',<value>);


CA_Util.addParam('sysparm_c_decsion',<value>);


CA_Util.getXML(respnse_function);




function respnse_function(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  //alert(answer);


}