Make change fields read only based on Standard change template

yamunapriya
Tera Contributor

Hi All, 

Could you please help me with the following scenario:

We have to make certain fields of the change request read only for standard type change. The field values are populated based on the Standard change template (values are stored in the table std_change_template). If the value is autopopulated from template then we have to make read only. Otherwise the filed should be editable. 

Thank you 

 

 

1 ACCEPTED SOLUTION

@yamunapriya I understood now, so in this case you should modify the client script Mark standard change fields readonly adding a condition there.

Please give it a try and let me know.

If I have answered your question, please mark my response as correct and helpful so that this thread can be closed and others can be benefited by this.

Thank you very much

Cheers
Alberto

View solution in original post

11 REPLIES 11

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi @yamunapriya 

please follow the procedure below in the Standard Change Properties section:

find_real_file.png

If I have answered your question, please mark my response as correct and helpful so that this thread can be closed and others can be benefited by this.

Thank you very much

Cheers
Alberto

@Alberto Consonni  Thank you , but I need the fields to be filled in by the user in case there is no value populated from the template.

There are 2 fields 1. Mandatory on dictionary level  2. Nonmandatory

will the above workaround resolve the issue?

@yamunapriya I understood now, so in this case you should modify the client script Mark standard change fields readonly adding a condition there.

Please give it a try and let me know.

If I have answered your question, please mark my response as correct and helpful so that this thread can be closed and others can be benefited by this.

Thank you very much

Cheers
Alberto

@Alberto Consonni : Can we create a separate client script or do we need to edit the existing one. 

The exisitnd client script to make fields read only is ;

function onLoad() {
var chgType = g_form.getValue("type");
var ga;
if (chgType == "standard") {
if (g_form.isNewRecord() || g_form.getUniqueValue() === -1 || g_form.getUniqueValue() === '-1'){
ga = new GlideAjax('StdChangeUtils');
ga.addParam('sysparm_name', 'ajaxFunction_getReadOnlyFieldsOnInsert');
ga.getXMLAnswer(markReadonly);
}
else {
ga = new GlideAjax('StdChangeUtils');
ga.addParam('sysparm_name', 'ajaxFunction_getReadOnlyFields');
ga.addParam('sysparm_sysId', g_form.getUniqueValue());
ga.addParam('sysparm_tableName', 'change_request');
ga.getXMLAnswer(markReadonly);
}
}
}

function markReadonly(answer){
if(answer){
var parsedAttributeNames = answer.split(',');
for(var i = 0; i < parsedAttributeNames.length; i++){
if(g_form.hasField(parsedAttributeNames[i]))
g_form.setReadOnly(parsedAttributeNames[i], true);
}
}