Set Category field in knowledge form readOnly

anasuyaray
Kilo Expert

Hi,

I am setting the fields in knowledge form read only based on some conditions.

I have written an onLoad client script which is working when the state is published or retired and current user is not the manager of the corresponding knowledge base.

I am doing a glideAjax call which is returning the right value.

After that I am setting the floowing fields readonly:

function setReadOnly(response) {

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

if(answer == 'false'){

  g_form.setReadOnly('text',true);

  g_form.setReadOnly('kb_knowledge_base',true);

  g_form.setReadOnly('kb_category',true);

  g_form.setReadOnly('short_description',true);

  g_form.setReadOnly('language',true);

  g_form.setReadOnly('valid_to',true);

  g_form.setReadOnly('direct',true);

  g_form.setReadOnly('parent',true);

  g_form.setReadOnly('article_type',true);

  g_form.setReadOnly('source',true);

  g_form.setReadOnly('image',true);

  g_form.setReadOnly('roles',true);

  g_form.setReadOnly('display_attachments',true);

  }

}

Everything is setting the value readOnly but category is not getting set. Category is dependent on knowledge base but I am setting knowledge base also as read only. Knowledge base is working fine.

Please help me.

Regards,
Anasuya

1 ACCEPTED SOLUTION

fschuster
ServiceNow Employee
ServiceNow Employee

Anasuya,



There is another Client Script called "Enable or disable form fields". It runs onChange, but its also executed onLoad due to the missing !isLoading check.


This script will mark the "kb_category" (KB version 3) or "category" (KB version 2) field as writeable again.



You might want to comment out the category fields in that script if you want your script to be triggered correctly. You can easily test this by setting the above mentioned script to inactive for a quick test.


View solution in original post

4 REPLIES 4

Chris York
Tera Expert

Are you sure you have the right field name? If you are working on the kb_knowledge table, the Category field is "category", not "kb_category".


fschuster
ServiceNow Employee
ServiceNow Employee

Anasuya,



There is another Client Script called "Enable or disable form fields". It runs onChange, but its also executed onLoad due to the missing !isLoading check.


This script will mark the "kb_category" (KB version 3) or "category" (KB version 2) field as writeable again.



You might want to comment out the category fields in that script if you want your script to be triggered correctly. You can easily test this by setting the above mentioned script to inactive for a quick test.


Hi Frank!



Thank you.


I have made the Enable or disable form fields client script inactive as we are using only kb version 3. All the knowledge bases are created with version 3. Hope that will not be a problem.


Only state field value was not read only but as per the requirement it should be always read only. So from dictionary entry I have made the value read only


fschuster
ServiceNow Employee
ServiceNow Employee

If you simply deactivated that script you will still receive changes to it during the next upgrade cycle in case there are changes. If you modified some code in that script, it will be considered "owned by you" and therefore it will be skipped during the next upgrade (again, only in case there are any changes). You can still review the skipped records after an upgrade and decide to apply the new version if applicable.