client script g_form.setReadOnly() no longer works in Sandiego

xiaix
Tera Guru

I have a Client Script on the sc_task table where I have the following code:

 

var variable_map_items = $("variable_map").querySelectorAll("item");
for (i = 0; i < variable_map_items.length; i++) {
	variable = variable_map_items[i].getAttribute("qname");
	g_form.setReadOnly("variables."+ variable, false);
}

 

I would like to mention that in my ROME instance (and earlier), the above code works great.

However, our DEV instance just upgraded to Sandiego and it is no longer working.

 

What changed in Sandiego where you can't do this anymore?

 

1 ACCEPTED SOLUTION

xiaix
Tera Guru

So, here's the real answer, which isn't mentioned anywhere in the docs!  Grrrrr!

San Diego - Take actions to keep "write roles" on Catalog Variables working 

 

Basically, I needed to insert a sys_property called glide.sc.evaluate.variables.write.access and set the value to false

Once I did that, everything worked like a charm.

View solution in original post

9 REPLIES 9

correct, it worked in an onLoad client script.

 

To replicate/show you on here, here is the code through the javascript executor (Press "Alt+Ctrl+Shift+j" to open the Javascript Executor.)

Before: field is read only

Mike_R_0-1667841738454.png

 

After executing, field is not read only

Mike_R_1-1667841751455.png

 

When I click "Run my code"... absolutely nothing happens.  Looks like I need to open a HI ticket.

xiaix
Tera Guru

Looking further, g_form.setMandatory() also no longer works in the same context as above in Sandiego

xiaix
Tera Guru

So, this is what we need to do now to make a variable non-readonly and allow users to update them:

 

var variable_map_items = $("variable_map").querySelectorAll("item");
for (i = 0; i < variable_map_items.length; i++) {
	variable = variable_map_items[i].getAttribute("qname");
	var e = form.getControl("variables."+ variable);
	if (e) {
		var el = document.getElementById('element.'+e.id);
		if (!el) {
			el = document.getElementById('element.'+e.id+'_read_only');
		}
		if (el) {
			fFound = true;
			if (thisTable == "sc_task") {
				//g_form.setReadOnly("variables."+ variable, false);
				
				var actualFormFieldInHTML = document.getElementById(e.id);  // This should be the hidden input field that stores the actual value that gets passed to the server when saved
				if (actualFormFieldInHTML){
					actualFormFieldInHTML.readOnly = false;
				}

				var actualFormFieldInHTML_ro = document.getElementById(e.id+'_read_only');
				if (actualFormFieldInHTML_ro){
					actualFormFieldInHTML_ro.readOnly = false;
				}

				if (actualFormFieldInHTML && actualFormFieldInHTML_ro){
					actualFormFieldInHTML_ro.addEventListener("change", function() {
						actualFormFieldInHTML.value = actualFormFieldInHTML_ro.value;
					}); 
				}
			}
		} else {consoleWarn("el NOT FOUND");}
	} else {consoleWarn("e NOT FOUND");}
}

 

The key was setting an event listener:

actualFormFieldInHTML_ro.addEventListener("change", function() {
	actualFormFieldInHTML.value = actualFormFieldInHTML_ro.value;
});

 

xiaix
Tera Guru

So, here's the real answer, which isn't mentioned anywhere in the docs!  Grrrrr!

San Diego - Take actions to keep "write roles" on Catalog Variables working 

 

Basically, I needed to insert a sys_property called glide.sc.evaluate.variables.write.access and set the value to false

Once I did that, everything worked like a charm.