The CreatorCon Call for Content is officially open! Get started here.

How can I make a field in Service Portal as read only?

Student1
Tera Contributor

Hello,

I have the following requirement.

I want to have a field on Service Portal's form, that is read only. It will contain a value but the end user can not change it.

Is this possible?Any ideas?

1 ACCEPTED SOLUTION

Hi,

you can create onload catalog client script and

1) set the UI Type as Mobile/ Service Portal so that this script executes only for portal and not for native

2) Applies to Catalog Item - true

3) Catalog item - Select your catalog item

4) Type - onLoad

5) Applies on Catalog Item view - true

function onLoad(){

g_form.setReadOnly('city', true);

}


find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

14 REPLIES 14

You need to create a Catalog UI Policy for this:

On your item go to:

find_real_file.png

 

find_real_file.png

 

Set up like this:

find_real_file.png

 

Save and enter Catalog UI Policy actions:

find_real_file.png

 

Like this:

find_real_file.png

 

Replace Job title with the field you want to be read only

Student1
Tera Contributor

It seems really helpful but in my case, it does not work. Any ideas?? Do I need to make a script also?

Do you use variable set on the Item? If so you can define a UI Policy on the Variable set in the same way instead.

find_real_file.png

 

find_real_file.png

 

In your case the script that @Ankur Bawiskar provided should work as well.

Ashley Snyder1
Giga Guru

While I love UI Policies, using Run Scripts is a bit complicated here as you'd still need something to key off of in the condition builder.

Create an onLoad Catalog Client Script that only runs in the Mobile/Service Portal UI Type, and put in g_form.setReadOnly('your_var_name',true);  This should set the variable Read Only, only within those UI Types and not Desktop.

Shekhar Deshin1
Mega Guru

Hi,

Seems like it is Single Line Variable you used.in Variables of catalog Item you can Set the Default
Value as 'XYZ' for City Variable.

You can use the UI policy for Catalog Item give the condition 'is not empty' and apply as Read Only.

here as per your scenario you want update the City variable by default name display before displaying on Service Portal.

Thanks,

Shekhar Deshingkar,