Madrid Service Portal g_form.setDisabled and g_form.setReadOnly do not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-14-2019 05:59 AM
For a Service Portal application I have found that the g_form.setReadOnly and the g_form.setDisabled functions do not affect the readonly value for sc_req_item variables from either a widget or a Client Script that is triggered by a display Business Rule.
I have confirmed that the g_form.setVisible and g_form.setDisplay does work as expected for both sc_req_item fields and variables and the g_form.setReadOnly does work for fields.
Please let me know if you have encountered this issue and found a solution. I need to be able to set read-only on various variables based on the group the user is in as well as on variable values in the sc_req_item.
Thank you in advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-14-2019 06:06 AM
Hi,
have a look at the solution provided in the below thread, it should fit your need:
If I have answered your question, please mark my response as correct and/or helpful so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
Thank you
Cheers
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-14-2019 06:35 AM
I have no issues getting the variables so this does not solve my problem. Thanks anyway.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-14-2019 06:45 AM
Hi Janet,
I read your question and can you share your code? It'll be much easier to come up with a solution if I have the whole picture.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-14-2019 09:10 AM
Code from the Client Script follows. Before the variables are readonly = false. After a variable is set to readonly = true, the readonly value is still false. After, anything setVisible as false is not displayed.
---------------------
function onLoad() {
if (g_scratchpad.akamaiCatalogItem && g_scratchpad.requestID) {
g_form.setVisible("watch_list", false);
g_form.setVisible("requested_for", false);
g_form.setVisible('variables.created_by', false);
g_form.setVisible('variables.label_tech_prerequisites', false);
g_form.setVisible('variables.technical_requirements_acknowledge', false);
var isReadOnly = g_form.isReadOnly("variables.requested_for");
console.log("requested_for isReadOnly before: " + isReadOnly);
g_form.setReadOnly("variables.requested_for", true);
g_form.setDisabled("variables.requested_for", true);
isReadOnly = g_form.isReadOnly("variables.requested_for");
console.log("requested_for isReadOnly after: " + isReadOnly);
isReadOnly = g_form.isReadOnly("variables.requestor_contact_method");
console.log("requestor_contact_method isReadOnly before: " + isReadOnly);
g_form.setReadOnly("variables.requestor_contact_method", true);
g_form.setDisabled("variables.requestor_contact_method", true);
isReadOnly = g_form.isReadOnly("variables.requestor_contact_method");
console.log("requestor_contact_method isReadOnly after: " + isReadOnly);
}
}
---------------------
Code from the Client Script in the widget follows. Console log before shows all fields and variables are readonly=false and after shows only the fields are readonly=true. After, anything setVisible as false is not displayed, all fields are readonly=true, and all variables are still readonly=false. From a forum suggestion I tried "variables[index].readonly = true;" which did change the readonly value but the the variable was still editable when displayed.
---------------------
$scope.$on('spModel.gForm.initialized', function(e, gFormInstance) {
initForm(gFormInstance);
});
var g_form;
function initForm(gFormInstance) {
if (gFormInstance.getTableName() == $scope.data.f.table){
g_form = gFormInstance;
console.log("initForm");
console.log($scope.data.f);
// Force all fields to be read only.
var fields = g_form.getFieldNames();
console.log("fields.length: " + fields.length);
for (var index=0; index < fields.length; index++) {
var name = fields[index];
g_form.setReadOnly(fields[index], true);
}
// Initial all the form variables to be read only.
var variables = $scope.data.f.variables;
console.log("variables.length: " + variables.length);
for (var index=0; index < variables.length; index++) {
var variable = 'variables.' + variables[index].name;
// variables[index].readonly = true;
g_form.setReadOnly(variable, true);
g_form.setDisabled(variable, true);
}
console.log($scope.data.f);
console.log("initForm DONE");
spNavStateManager.register($scope.data.table, _save, g_form);
$scope.isPageReady = true;
$timeout(function() {
$rootScope.$emit('spModel.gForm.rendered', g_form);
}, 175);
}
}
------------------------------